This is where you can share your code for solving the Stopwatch exercise ![]()
Okay so the stopwatch challenge sounds deceptively simple but the timing part is where it gets tricky. I always think about that live concert feedback loop I had once. A tiny bit of latency and the whole thing falls apart. The real challenge here is managing state updates without introducing jank, especially if you’re trying to hit 60fps. Using requestAnimationFrame for the updates instead of setInterval is usually key for smooth animations. You want to tie your updates to the browser’s repaint cycle, not just a fixed interval.
let startTime;
let animationFrameId;
function updateTimer(timestamp) {
if (!startTime) startTime = timestamp;
const elapsed = timestamp - startTime;
// Update your display here with 'elapsed'
animationFrameId = requestAnimationFrame(updateTimer);
}
// To start:
// animationFrameId = requestAnimationFrame(updateTimer);
// To stop:
// cancelAnimationFrame(animationFrameId);