Simulation of a stopwatch in javascript