Stopwatch / Timer – JavaScript Advanced Tutorial




A video in our JavaScript Advanced Tutorial series.

In this video we create a stopwatch that has start, pause, resume, and reset functionality. We use the setTimeout function and do some basic math and modulus.

Original source


29 responses to “Stopwatch / Timer – JavaScript Advanced Tutorial”

  1. This is a good tutorial but how do you make a countdown timer? I tried to set the timer= 20 and change the timer++ to timer– but it does some weird thing… The secs doesn't reset back to 0 but just keeps incrementing to 64 or 65 etc

  2. So I attempted to debug the reset button issue with Chrome's Developer Tools. After reset() is called, it's followed by one more iteration of increment(), which is why it stops at :01. Can anyone explain why?

  3. Thanks for the video!!! At 11:50, you run into an issue where the reset button has to be hit twice to fully set the display at 00:00:00. Is there a way to resolve this issue? Thank! (I know the vid is almost 4 years old, but I am hoping that someone can help.) Thanks in advance!

  4. for people haveing trouble with the code not working beyond 60 seconds:

    declare another variable right under "var time = 0"
    call it "var secs = 0".

    replace in increment() function "var secs = Math.floor(time/10)" with "secs++;" and ad this if statement in the increment() function "if(secs % 60 == 0){ secs = 0; }

  5. I got a question, I've done EVERYTHING you've done, it's exactly the same, checked it about 5 times, but the seconds continue to count after they hit 60, is there a way to make it reset when it hits 60 so it becomes 0 again? 

Leave a Reply