Intermediate
A stopwatch that really stops
Build a stopwatch. #time shows the elapsed seconds with one decimal (0.0, 0.1, …). The button #toggle says Start when stopped and Stop while running.
While running, an interval adds one tenth of a second every 100 ms. When stopped, the time must freeze: the interval has to be cleared, not left running in the background.
Use an effect that depends on running, starts an interval when it is true, and returns a cleanup.
What Check tests
- It starts at
0.0with aStartbutton - After Start, the time goes up
- After Stop, the time freezes
- Start again continues from where it stopped
- The effect clears its interval
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.