Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
No puedo entender por qué mi objeto de temporizador no funciona

Traté de codificar un temporizador de JavaScript que incrementaría un valor cada segundo y actualizaría el HTML interno de un elemento DOM para mostrar la hora. El primer tick funciona, pero después de eso timerEngine.time no está definido y al incrementarlo en tick() se produce NaN. ¿Por qué la variable no está definida?

Aquí está el código:

 const timerEngine = { time: 0, timerID: -1, tick() { this.time++; if (this.time % 60 < 10) document.getElementById("timer").innerHTML = `${Math.floor(this.time / 60)}:0${this.time % 60}`; else document.getElementById("timer").innerHTML = `${Math.floor(this.time / 60)}:${this.time % 60}`; }, start() { if (this.timerID === -1) this.timerID = setInterval(this.tick, 1000); }, stop() { if (this.timerID !== -1) { clearInterval(this.timerID); this.timerID = -1; } }, reset() { this.stop(); this.time = -1; this.tick(); } }

El temporizador se inicia en una función:

 someFunction() { // some code timerEngine.reset(); timerEngine.start(); }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!