How to make a countdown timer on nodejs

Asked

Viewed 236 times

-2

My intention is to make a countdown timer in javascript, even if no one is on the site the timer continues to count unbelievably.

How can I do that?

Thank you.

  • It can be with Nodejs even.

  • 1

    So when you have a code for how you tried, with any problem or doubt, you can edit your question, mcve.

  • By the way, if you want to do Javascript with you, as long as someone is always on the right site?

  • Just to reinforce: MVCE

1 answer

1

"timer decreasing in javascript, even if no one is on the site the timer continues to count unbelievably"

Why use a timer then? you can use the current date and decide what to do. For example, taking colors into account:

var cores = ['#faa', '#afa', '#aaf'];

you can then know how many minutes of such a day have passed and do some math...

var agora = new Date();
var minutosEsteDia = (agora.getHours() * 60) + agora.getMinutes();
var meiasHoras = minutosEsteDia / 30;
var cor = Math.round(meiasHoras % (cores.length - 1));

Now you’ve given me the position 2, ie: #aaf. Let’s see what happens in half an hour :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.