Stopwatch with laps that highlights the fastest and slowest
Build a stopwatch for a running coach. It measures the total running time, can be stopped and resumed, and records laps: each lap is the running time since the previous lap (or since the start). The coach wants to see at a glance which lap was fastest and which was slowest.
role="timer", formatted as MM:SS.cc (two-digit minutes, two-digit seconds, two-digit hundredths), for example 00:00.00, 00:07.45, 01:01.23. Round down to the hundredth: 1,239ms is 00:01.23.| Button | Behavior |
|---|---|
| Start / Stop | One button (or two) whose text is Start while stopped and Stop while running. Start begins or resumes timing; Stop freezes the display at the exact running time at the moment of the click. |
| Lap | Enabled only while running. Records a lap. |
| Reset | Enabled only while stopped and there is something to clear (time above zero or at least one lap). Sets the time back to 00:00.00 and removes every lap. |
A disabled button has the disabled attribute or aria-disabled="true".
<li> per lap, newest first. Each item shows Lap N and the lap time in MM:SS.cc, for example Lap 2 00:01.20.Fastest to the item of the shortest lap and Slowest to the item of the longest lap. If several laps tie, mark the lowest-numbered one. If every lap has the same time, mark none. With a single lap, mark nothing.Start 00:00.00 → counting
2.5s later, Lap Lap 1 00:02.50
1.2s later, Lap Lap 2 00:01.20
Stop, wait 10s, Start (the paused 10s doesn't count)
3s later, Lap Lap 3 00:03.00
Stop 00:06.70
Lap 3 00:03.00 Slowest
Lap 2 00:01.20 Fastest
Lap 1 00:02.50
Date.now() or performance.now()) instead of counting ticks.01:00.00, not 00:60.00.The tests replace Date, setTimeout, setInterval, requestAnimationFrame and performance.now with a fake clock, move time forward (sometimes firing a late timer only once after a long gap), click your buttons and read the screen like a user would. You don’t need test ids, class names or an exact HTML structure. They check:
role="timer" element: within 0.1s of the real time while running, and exact after Stop,<button> (or role="button") elements whose text is Start, Stop, Lap or Reset, and whether they are disabled,<li> items that contain Lap N: their order, lap times, and the Fastest / Slowest labels.Capitalization and extra spacing don’t matter.