forked from ShaifArfan/one-page-website-html-css-project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript8.js
82 lines (68 loc) · 2.19 KB
/
script8.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var clicks = 0;
var refreshRate = 1; //time in milliseconds
var currentYearPrefix = 26;
function updateTime() {
let currentTime = new Date();
const christmasDate = new Date('2/14/20' + currentYearPrefix) //2021
let milliseconds;
let days;
let hours;
let minutes;
let seconds;
milliseconds = Math.abs(currentTime - christmasDate);
days = Math.floor(milliseconds / (1000 * 60 * 60 * 24));
hours = Math.floor(milliseconds / (1000 * 60 * 60));
minutes = Math.floor(milliseconds / (1000 * 60));
seconds = Math.floor(milliseconds / (1000));
var formattedHours = hours % 24
var formattedMinutes = minutes % 60
var formattedSeconds = seconds % 60
const fullDays = (days + " days");
const fullHours = (hours + " hours");
const fullMinutes = (minutes + " minutes");
const fullSeconds = (seconds + " seconds");
const fullMilliseconds = (milliseconds + " milliseconds");
const fullTime = (days + " days " + formattedHours + " hours " + formattedMinutes + " minutes " + formattedSeconds + " seconds.") //MAIN FORMAT
var ft = document.getElementById("fullTime")
var fd = document.getElementById("days")
var fh = document.getElementById("hours")
var fmin = document.getElementById("minutes")
var fs = document.getElementById("seconds")
var fmill = document.getElementById("milliseconds")
ft.innerHTML = fullTime
fd.innerHTML = fullDays
fh.innerHTML = fullHours
fmin.innerHTML = fullMinutes
fs.innerHTML = fullSeconds
fmill.innerHTML = fullMilliseconds
setTimeout(updateTime, refreshRate);
document.addEventListener('click', function() {
clicks++;
if (clicks == 1) {
ft.style.display = "none"
fd.style.display = "block"
}
else if (clicks == 2) {
fd.style.display = "none"
fh.style.display = "block"
}
else if (clicks == 3) {
fh.style.display = "none"
fmin.style.display = "block"
}
else if (clicks == 4) {
fmin.style.display = "none"
fs.style.display = "block"
}
else if (clicks == 5) {
fs.style.display = "none"
fmill.style.display = "block"
}
else {
clicks = 0;
fmill.style.display = "none"
ft.style.display = "block"
}
})
}
updateTime();