Stop function if condition fulfill | SoloLearn: Learn to code for FREE!

+1

Stop function if condition fulfill

I want when the condition fulfil then stop setInterval function. https://code.sololearn.com/Wmgpl2k1YnI9/?ref=app

6/22/2018 11:31:46 AM

Satish Kumar Sharma

3 Answers

New Answer

+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. ~