Countdown Timer in JavaScript

Build a countdown timer

IntermediateMini ProjectsExample 4 of 20
countdown-timer.js
1class Countdown {
2 constructor(target) { this.target = target; }
3 start(callback) {
4 const interval = setInterval(() => {
5 const remaining = this.target - Date.now();
6 if(remaining <= 0) { clearInterval(interval); callback(); }
7 else callback(remaining);
8 }, 1000);
9 }
10}

Output

// Countdown timer

What's going on

Countdown Timer counts down to target time.