+ 1
Stop function if condition fulfill
I want when the condition fulfil then stop setInterval function. https://code.sololearn.com/Wmgpl2k1YnI9/?ref=app
3 Answers
+ 16
var myVar = setInterval(myTimer, 1000);
var t = 5;
function myTimer() {
var n = t--;
if(n <= 0){
myStopFunction();
}
document.getElementById("demo").innerHTML = n;
}
function myStopFunction() {
clearInterval(myVar);
}
//Like this??
+ 1
Satish it works you just forgot to close the function with a closing curly brace " } " at the myStopFunction
+ 1
i need this answer and finally i got this
thanks a lot Valen.H. ~