Here is my code (that is inside a button.click()
function)
if(inBreak === true) {
inBreak = false;
var timer = setInterval(function() {
if(seconds == 0) {
console.log(minutes);
minutes -= 1;
seconds = 59;
} else {
seconds -= 1;
}
$('.minutes').text(minutes);
$('.seconds').text(seconds);
}, 1000);
} else {
inBreak = true;
console.log(timer);
clearInterval(timer);
}
The problem is clearInterval(timer)
not working because timer isn't defined, but I defined it the first time I clicked (and used the function).
So do you have an idea for accomplish that ? I tried let / const instead var but not working anyway :(s