Stopwatch
UI Coding
Medium
30 min
timers
effects
state
accessibility
Build a stopwatch.
Requirements
- The display shows elapsed time as
MM:SS.cc(minutes, seconds, hundredths), starting at00:00.00. From one hour onwards, showH:MM:SS.cc. - A primary button toggles Start / Stop. Stopping freezes the display. Starting again continues from where it stopped.
- A secondary button:
- shows Lap while running, and records the current split
- shows Reset while stopped, and clears the time and laps. It's disabled at
00:00.00.
- Laps appear in a numbered list, newest first, showing each lap's own duration ("Lap 2 — 00:03.41").
- The time must be accurate: after 60 real seconds it must read 60 seconds, even if the tab was in the background or the main thread was busy.
- Accessibility: the display uses
role="timer". Buttons have clear names. Keyboard shortcuts are optional, but don't hijack keys while the user is typing in a field.
Follow-up
- Why is "add 10 ms every 10 ms" wrong?
setIntervalorrequestAnimationFramefor updating the display?Date.now()orperformance.now()?
Spotted a mistake or a rights concern? Report an issue