Update script.js
This commit is contained in:
parent
68e28f4cc2
commit
a94d81e563
62
script.js
62
script.js
@ -1,31 +1,31 @@
|
|||||||
const daysEl =document.getElementById ('days');
|
const daysEl =document.getElementById ('days');
|
||||||
const hoursEl =document.getElementById ('hours');
|
const hoursEl =document.getElementById ('hours');
|
||||||
const minutesEl =document.getElementById ('minutes');
|
const minutesEl =document.getElementById ('minutes');
|
||||||
const secondsEl =document.getElementById ('seconds');
|
const secondsEl =document.getElementById ('seconds');
|
||||||
|
|
||||||
const newYears = '1 Jan 2023';
|
const newYears = '22 Oct 2022';
|
||||||
|
|
||||||
function countdown() {
|
function countdown() {
|
||||||
const newYearsDate = new Date(newYears);
|
const newYearsDate = new Date(newYears);
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
|
|
||||||
|
|
||||||
const totalSeconds = new Date(newYearsDate - currentDate) / 1000;
|
const totalSeconds = new Date(newYearsDate - currentDate) / 1000;
|
||||||
|
|
||||||
const days = Math.floor(totalSeconds / 3600 / 24);
|
const days = Math.floor(totalSeconds / 3600 / 24);
|
||||||
const hours = Math.floor(totalSeconds / 3600) % 24;
|
const hours = Math.floor(totalSeconds / 3600) % 24;
|
||||||
const minutes = Math.floor(totalSeconds / 60) % 60;
|
const minutes = Math.floor(totalSeconds / 60) % 60;
|
||||||
const seconds =Math.floor(totalSeconds) % 60;
|
const seconds =Math.floor(totalSeconds) % 60;
|
||||||
|
|
||||||
daysEl.innerHTML = days;
|
daysEl.innerHTML = days;
|
||||||
hoursEl.innerHTML = hours;
|
hoursEl.innerHTML = hours;
|
||||||
minutesEl.innerHTML = minutes;
|
minutesEl.innerHTML = minutes;
|
||||||
secondsEl.innerHTML = seconds;
|
secondsEl.innerHTML = seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Initial call
|
//Initial call
|
||||||
countdown();
|
countdown();
|
||||||
|
|
||||||
setInterval(countdown, 1000);
|
setInterval(countdown, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user