Stopwatch

A countdown timer with 'start', 'pause' and 'reset' functionality.

We'll cover the following...

Exercise:

Create a stopwatch that counts down from a given number of seconds in the format mm:ss. Make it possible to start, pause, and reset the countdown. Make sure you can pass a callback function to the timer that is called when the displayed value is updated.

Solution:

The main part of this exercise boils down to modeling. If you find the right model, your life will be easy. If you use the wrong model, implementation will not only be hard, but the stopwatch might not reflect reality. Let’s define the state space of the application: ...