Stop function if condition fulfill | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Stop function if condition fulfill

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

22nd Jun 2018, 11:31 AM
Satish Kumar Sharma
Satish Kumar Sharma - avatar
3 Respostas
+ 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??
22nd Jun 2018, 11:34 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
Satish it works you just forgot to close the function with a closing curly brace " } " at the myStopFunction
22nd Jun 2018, 12:07 PM
Peter Claver
Peter Claver - avatar
+ 1
i need this answer and finally i got this thanks a lot Valen.H. ~
23rd Jun 2018, 9:04 AM
Alex
Alex - avatar