+ 3
How can I make a button that it can stop timer??
7 odpowiedzi
+ 4
https://code.sololearn.com/WpZPc8NSZ7J3/?ref=app
+ 2
Ok, help me.how?
+ 2
Yes it's correct but setInterval() is in a function
and I can't do it
+ 2
if I want to use of clearInterval() I must save the setInterval() in a variable
+ 1
I could to learn some thing more from you. Thanks alot
0
What you could do is set a different button (or the same one, whatever you like), and have it go to a function that clears the previous interval. This can be done by using the clearInterval() function, with the name of the variable that sets the interval within the brackets. For this to work however, the function that sets the interval must be declared as a variable, so it can be referenced to within the clearInterval function.
For example:
var setI = setInterval(b, 1000);
function c(){
clearInterval(setI);
} //This function should be called when some button is pressed
0
Thanks