-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
26 lines (24 loc) · 867 Bytes
/
script.js
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
const daysEl=document.getElementById('days');
const hoursEl=document.getElementById('hours');
const minsEl=document.getElementById('mins');
const secondsEl=document.getElementById('seconds');
const newyearDate='1 jan 2024';
function countdown(){
const newyear=new Date(newyearDate);
const currentdate=new Date();
const totalSec=(newyear-currentdate)/1000;
const days=Math.floor(totalSec/3600/24);
const hours=Math.floor(totalSec/3600)%24;
const mins=Math.floor(totalSec/60)%60;
const sec=Math.floor(totalSec)%60;
daysEl.innerHTML=correct(days);
hoursEl.innerHTML=correct(hours);
minsEl.innerHTML=correct(mins);
secondsEl.innerHTML=correct(sec);
}
function correct(time) {
// return time<10 ? (`0${time}`) : time ;
return time<10 ? '0'+time : time ;
}
countdown();
setInterval(countdown,1000);