I've got issue with stopping setInterval
timer. I know It should stop after using claeerInterval
, but in my case something wrong.
This is part of code what I have:
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
var tmr = setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
function beginTimer() {
var fiveMinutes = 60 * 5,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
}
function gameOver() {
// some more code
clearInterval(tmr); // there throws an error
}
And after It I got an error:
Uncaught ReferenceError: tmr is not defined
Have you ideas what's wrong with It? should I make It public or something else?