Hello! I’m making a Javascript countdown timer and it’s almost complete, but when I try to call my countdown function with setInterval, it doesn’t seem to be initiating the countdown. I was seeing if someone can help me fix this. Thanks!
const date = new Date;
const countdownDate = new Date("February 2, 2023 1:40");
const difference = countdownDate.getTime() - date.getTime();
const second = document.getElementById("secs");
const minute = document.getElementById("mins");
const hour = document.getElementById("hours");
const days = document.getElementById("days");
console.log(difference);
function remainingTime(day, hours, minutes, seconds){
day = Math.floor(difference * 1.1574074074074E-8);
hours = Math.floor((difference % 24));
minutes =
seconds =
second.innerHTML = seconds;
minute.innerHTML = minutes;
hour.innerHTML = hours;
days.innerHTML = day;
}
remainingTime()
const value = setInterval(remainingTime, 1000);
I was able to get the days, but I’m still confused on how to get the hours, minutes, etc. because I can’t think of any other way than the one listed above. I’m unsure if there’s a formula, but yeah, I’m confused. I attempted to get difference to execute multiple times in hours but I’m not sure if that’s working because it returns a different value each time I refresh the page.