How to use clearInterval and setInterval in 2 buttons | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to use clearInterval and setInterval in 2 buttons

I want to make a timer with a start and stop button but putting setInterval in a different onclick function puts it out of the scope of the clearInterval onclick function. Help? https://code.sololearn.com/WOFp8gzRooBE/?ref=app

10th Aug 2018, 6:51 AM
Marvin Lee
Marvin Lee - avatar
4 Answers
+ 3
You were declaring variable go in only start function so it was out of scope for other functions. Also set setInterval for 10ms (100 in it) , its good for visualization. Hope this helps ☺️☺️.
10th Aug 2018, 7:01 AM
Meet Mehta
Meet Mehta - avatar
10th Aug 2018, 7:00 AM
Meet Mehta
Meet Mehta - avatar
+ 1
Yes it did, thanks Meet Mehta
10th Aug 2018, 7:24 AM
Marvin Lee
Marvin Lee - avatar
+ 1
:)
10th Aug 2018, 7:25 AM
Meet Mehta
Meet Mehta - avatar