Back to projects

Stopwatch & Countdown Timer

A stopwatch and countdown timer built in vanilla JavaScript that tracks elapsed time accurately without clock drift from browser tab throttling.

https://bamacharanchhandogi.github.io/Stopwatch/

The Problem

Making a timer in JavaScript seems very easy at first, but using a basic setInterval causes the clock to slowly drift and become inaccurate when you switch browser tabs or your laptop sleeps.

How It Solves It

This project builds both a high-precision stopwatch and countdown timer. Instead of just adding numbers every second, it calculates the exact time difference between the current moment and when you pressed start (performance.now()), so the clock stays 100% accurate even if the tab is running in the background.

How It's Built

  • Timestamp Delta Calculation: Keeps lap times and countdowns accurate down to the millisecond.
  • Lap Recorder: Saves split laps in a clean scrollable list so you can track lap intervals.
  • Keyboard Shortcuts: Start and stop with Space, reset with R, and log laps with L.

What It Means

A fun exercise in browser event loops and understanding how JavaScript handles time and intervals.