Report this

What is the reason for this report?

how to auto restart a countdown timer

Posted on November 10, 2020

Ive managed to follow instructions from a website to create a countdown timer which is very simular to this one: (https://www.digitalocean.com/community/tutorials/js-building-countdown-timer#prerequisites). What i cant get it to do is automatically reset. ive tried various different ways but to no success. ive got 3 timers on a page all counting down to zero:

  1. counts down to 8:00pm each day.
  2. counts down to 8:15pm each Wednesday.
  3. counts down to 8:30pm on the 1st of each month. any ideas on how i can do this? cheers in advance.


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

you’ll need to add a function to check if the target time has been reached and, if so, reset the timer to its starting value. You can do this by comparing the current time and the target time.

Here’s a basic idea of how to achieve this:

Create a function that will set the target time for each of your countdown timers, then modify your countdown function to call the function when the timer reaches 0, and then call itself again.

Then you can call the countdown function for each of your timers, passing the appropriate timer type (daily, weekly, or monthly)

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.