-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (22 loc) · 906 Bytes
/
script.js
File metadata and controls
30 lines (22 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const daysEl = document.getElementById("days");
const hoursEl = document.getElementById("hours");
const minsEl = document.getElementById("mins");
const secsEl = document.getElementById("secs");
const newYearDay = "1 jan 2021"
function countdownTimer(){
console.log("In timer");
const newYearFDate = new Date(newYearDay);
const currentTime = new Date();
const dateDiffInSeconds = (newYearFDate - currentTime)/1000;
const days = Math.floor(dateDiffInSeconds / 3600 / 24 );
const hours = Math.floor(dateDiffInSeconds / 3600 ) % 24 ;
const minutes = Math.floor(dateDiffInSeconds / 60 ) % 60;
const seconds = Math.floor(dateDiffInSeconds) % 60;
console.log(days,hours,minutes,seconds);
daysEl.innerHTML = days;
hoursEl.innerHTML = hours;
minsEl.innerHTML = minutes;
secsEl.innerHTML = seconds;
}
countdownTimer();
setInterval(countdownTimer,1000);