-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (32 loc) · 1.13 KB
/
Copy pathscript.js
File metadata and controls
40 lines (32 loc) · 1.13 KB
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
31
32
33
34
35
36
37
38
39
40
const newYears = '1 December 2024';
const targetEl = document.querySelector('h1');
const targetEvent = "Fourth Semester";
targetEl.innerHTML=targetEvent;
const daysEl = document.getElementById('days');
const hoursEl = document.getElementById('hours');
const minuteEl = document.getElementById('minutes');
const secondEl = document.getElementById('seconds');
function countdown(){
const newYearDate = new Date(newYears);
const currentDate = new Date();
const totalSeconds = Math.floor((newYearDate-currentDate)/1000);
const minute = Math.floor(totalSeconds/60)%60;
const hours = Math.floor(totalSeconds/3600)%24;
const days = Math.floor(totalSeconds/3600/24);
const seconds = totalSeconds % 60 ;
console.log(days,hours,minute,seconds);
daysEl.innerHTML = timeFormat(days);
hoursEl.innerHTML = timeFormat(hours);
minuteEl.innerHTML = timeFormat(minute);
secondEl.innerHTML = timeFormat(seconds);
}
function timeFormat(time){
if(time<10){
return `0${time}`;
}else{
return time;
}
}
//initial call
countdown();
setInterval(countdown,1000);