I have a code that counts down from 20 to 0. At this point the user has to do certain tasks and when he completes, he presses a button. At the time he presses the button, the counter must stop in the exact second it was pressed. Here are the codes:
JavaScript:
var count = new Number();
var count = 21;
function start(){
if((count - 1) >= 0){
count = count - 1;
tempo.innerText=count;
setTimeout('start();',1000);
console.log("tempo:" + count);
}
}
I tried to create the following if to stop as soon as the button is disabled
(which in the case is at the exact moment it is clicked and this is important):
if(document.getElementById("myBtn").disabled == true){
clearTimeout(count);
}
But this if does not work and I can not think of anything else.