0
I have a code that counts backwards from 20 to 0. At that time, the user has to do certain tasks and when completed, he presses a button. The minute he pushes the button, the counter has to stop at the exact second it was pressed. Follows 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 this case is the exact moment it is clicked and this is important):
if(document.getElementById("myBtn").disabled == true){
clearTimeout(count);
}
But that if doesn’t work and I can’t think of anything else.
it wasn’t me who gave the -1, I think who gave it was because there’s the stop button count!
– user60252