Problem
Build a stopwatch component with Start, Pause, and Stop controls.
Requirements
- Render three buttons: Start, Pause, and Stop.
- Start — begins counting up. On the first start the timer runs from zero.
- Pause — freezes the timer at the current time. Clicking Start again resumes from where it was paused.
- Stop — stops the timer and resets the display back to zero.
Hints / Approach
- Keep elapsed time in state as milliseconds so pause/resume just keeps accumulating; format it as
mm:ss(ormm:ss:csfor centiseconds) for display. - Drive ticks with
setInterval; clear the interval on pause and on stop. - To avoid drift, store
startTimestamp = Date.now() - elapsedon (re)start and setelapsed = Date.now() - startTimestampon each tick — don't just doelapsed += interval. - Stop clears the interval and sets
elapsedback to0; guard against starting an already-running timer.
No reference solution provided.