-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (48 loc) · 1.09 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
51
52
const times = document.querySelectorAll(".box .time");
const startBtn = document.querySelector(".start");
const stopBtn = document.querySelector(".stop");
const restartBtn = document.querySelector(".restart");
//
let hours = 99;
let min = 59;
let sec = 45;
let seconds;
startBtn.addEventListener("click", timeChanger);
stopBtn.addEventListener("click", function () {
clearInterval(seconds);
});
restartBtn.addEventListener("click", function () {
hours = 0;
min = 0;
sec = 0;
clearInterval(seconds);
timeChanger();
});
//
function timeChanger() {
seconds = setInterval(() => {
content();
if (sec + 1 < 60) {
sec++;
} else {
sec = 0;
min++;
if (min === 60) {
min = 0;
hours++;
if (hours == 100) {
hours = 0;
min = 0;
sec = 0;
content();
clearInterval(seconds);
}
}
}
}, 1000);
}
function content() {
times[2].textContent = sec < 10 ? "0" + sec : sec;
times[1].textContent = min < 10 ? "0" + min : min;
times[0].textContent = hours < 10 ? "0" + hours : hours;
}