-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (23 loc) · 872 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
27
28
29
30
const daysE1 = document.getElementById('days')
const hoursE1 = document.getElementById('hours')
const minutesE1 = document.getElementById('minutes')
const secondsE1 = document.getElementById('seconds')
const wordCup = '21 Nov 2022 7:00'
function countdown() {
const wordCupDate = new Date(wordCup)
const currentDate = new Date()
const totalSeconds = (wordCupDate - currentDate) / 1000
const days = Math.floor(totalSeconds / 3600 / 24)
const hours = Math.floor(totalSeconds / 3600) % 24
const minutes = Math.floor(totalSeconds / 60) % 60
const seconds = Math.floor(totalSeconds) % 60
daysE1.innerHTML = days
hoursE1.innerHTML = formatTime(hours)
minutesE1.innerHTML = formatTime(minutes)
secondsE1.innerHTML = formatTime(seconds)
}
function formatTime(time) {
return time < 10 ? `0${time}` : time
}
countdown()
setInterval(countdown, 1000);