-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (39 loc) · 1.26 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const second = 1000
const minute = second * 60
const hour = minute * 60
const day = hour * 24
const kickOffWorldCupDate = new Date('2026-06-08 17:00:00 UTC+2') // (the year when it starts-the month-the day the hour-the minute-the second)
// if the world cup starts, you just change the date.
function zeroLeft (number) {
return String(number).padStart(2, '0')
}
function diffKickOffDateWorldCup () {
const currentDate = new Date().getTime()
return kickOffWorldCupDate.getTime() - currentDate
}
function setCountDown (element, value) {
document.querySelector(`.${element}`).innerHTML = value
}
function diffDay (diff) {
return Math.floor(diff / day)
}
function diffHour (diff) {
const round = Math.floor(diff % day / hour)
return zeroLeft(round)
}
function diffMinute (diff) {
const round = Math.floor(diff % hour / minute)
return zeroLeft(round)
}
function diffSecond (diff) {
const round = Math.floor(diff % minute / second)
return zeroLeft(round)
}
function countDown () {
const diff = diffKickOffDateWorldCup()
setCountDown('days', diffDay(diff))
setCountDown('hours', diffHour(diff))
setCountDown('minutes', diffMinute(diff))
setCountDown('seconds', diffSecond(diff))
}
window.load = setInterval(countDown, 1000)