+ 3

How can I make a button that it can stop timer??

https://code.sololearn.com/W0QPKD16zqpo/?ref=app

24th Feb 2018, 9:20 PM
Sina
Sina - avatar
7 Respuestas
+ 4
https://code.sololearn.com/WpZPc8NSZ7J3/?ref=app
24th Feb 2018, 9:40 PM
Hasan Jafarov
Hasan Jafarov - avatar
+ 2
Ok, help me.how?
24th Feb 2018, 9:32 PM
Sina
Sina - avatar
+ 2
Yes it's correct but setInterval() is in a function and I can't do it
24th Feb 2018, 9:38 PM
Sina
Sina - avatar
+ 2
if I want to use of clearInterval() I must save the setInterval() in a variable
24th Feb 2018, 9:39 PM
Sina
Sina - avatar
+ 1
I could to learn some thing more from you. Thanks alot
25th Feb 2018, 8:03 AM
Sina
Sina - avatar
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
24th Feb 2018, 9:36 PM
Faisal
Faisal - avatar
0
Thanks
25th Feb 2018, 7:58 AM
Sina
Sina - avatar