Free

Pomodoro Timer

A timer that proves on screen why setInterval is not a clock.

  • JavaScript
  • SVG
  • Web Audio
  • HTML

About this project

A 25/5/15 pomodoro timer with a circular SVG progress ring, configurable lengths, a session counter, and an end-of-session chime synthesised in the browser rather than loaded from a sound file.

It is built around the most common bug in beginner timer projects: setInterval(fn, 1000) does not promise to run fn every second, only that it will not run any sooner. The real gap stretches with whatever else the page is doing, and a backgrounded tab is throttled deliberately. Every tick that assumes exactly one second passed loses whatever extra time actually elapsed, permanently, and always in the same direction.

The fix is not a smaller interval or a correction factor — it is to stop counting and derive every reading from one absolute timestamp. To prove the point, this timer runs a deliberately naive counter alongside the real one and shows you both, along with the longest gap the browser actually left between ticks. Hide the tab for a minute and come back to see the difference.

What you will learn

  • Understand why setInterval drifts, and why the drift only ever runs one way
  • Derive a countdown from an absolute target timestamp instead of decrementing a counter
  • Animate an SVG progress ring with stroke-dasharray, with no library
  • Synthesise a sound with the Web Audio API rather than shipping an audio file
  • Validate user input by writing the corrected value back, so the screen never disagrees with the program

Before you start

  • JavaScript basics — functions, events and setInterval
  • A browser and a text editor. Nothing to install.

New to JavaScript? The free JavaScript course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.