Countdown Counter

I have followed the guidelines in the Inspirational post: “Live countdown timer” https://www.editorx.com/inspiration/site/live-countdown-timer

But I encounter a problem and I hope someone can help me resolve it:

The example used in the guidelines operate with 2-digits number of days

My event is +200 days away – so 3-digit number of days – I have made the text element 3 digits instead of 2; tried to do so just for days as well as for all (days, hours, minutes, days) … But its not working: it displays only 2-digit… so missing the 2… in 247 days to go…

I would really appreciate any help!

*I am no coder…

const countDownDate = new Date(“Mar 02, 2024 10:00:00 GMT -09:00”).getTime();

$w.onReady(function () {

startCountDown();

});

// COUNTDOWN - Set the date we’re counting down to

function startCountDown() {

// set the clock for the first time

getDistanceOfTimer();

//show the clock

$w(‘#countdownContainer’).show();

// Update the count down every 1 second

setInterval(function () {

   getDistanceOfTimer(); 

}, 1000);

}

function getDistanceOfTimer() {

// Get today’s date and time

const now = new Date().getTime();

// Find the distance between now and the countdown date

const distance = countDownDate - now;

// Time calculations for days, hours, minutes and seconds

let days = Math.floor(distance / (1000 60 60 24));

let hours = Math.floor((distance % (1000 60 60 24)) / (1000 60 60));

let minutes = Math.floor((distance % (1000 60 60)) / (1000 60));

let seconds = Math.floor((distance % (1000 60)) / 1000);

console.log(seconds);

$w(‘#days’).text = (‘0’ + days.toString()).slice(-2);

$w(‘#hours’).text = (‘0’ + hours.toString()).slice(-2);

$w(‘#minutes’).text = (‘0’ + minutes.toString()).slice(-2);

$w(‘#seconds’).text = (‘0’ + seconds.toString()).slice(-2);

}


Hey @polarhusky !

I’d recommend checking out the Velo forum for things related to code :slight_smile:

Let me know how it goes. Good luck!