Command Palette

Search for a command to run...

Hectal
Phase 8: Refs and the DOM
React · Exercise 2 of 6 PreviousNext
Intermediate

Fix the stopwatch that won't stop

This stopwatch keeps its interval id in a normal variable, so Stop doesn't work. Fix it with a ref.

Keep the ids: the time shows in id="time" (it starts at 0.0), and the buttons are id="start", id="stop" and id="reset". Reset stops the clock and shows 0.0.

Pressing Start twice must not make the clock run faster.

What Check tests

  1. It starts at 0.0
  2. Start makes the time go up
  3. Stop really stops the clock
  4. Reset shows 0.0 and stays there
  5. Pressing Start twice doesn't make it run twice as fast

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.