-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
66 lines (60 loc) · 1.39 KB
/
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
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
let seconds = 0;
let tens = 0;
let mint = 0;
let hour = 0;
let getSeconds = document.querySelector(".seconds");
let getTens = document.querySelector(".tens");
let getMint = document.querySelector(".mint");
let getHour = document.querySelector(".hour");
let btnStart = document.querySelector(".btn-start");
let btnStop = document.querySelector(".btn-stop");
let btnReset = document.querySelector(".btn-reset");
let interval;
btnStart.addEventListener("click", () => {
if (!interval) {
interval = setInterval(startTimer, 10);
}
});
btnStop.addEventListener("click", () => {
clearInterval(interval);
interval = null;
});
btnReset.addEventListener("click", () => {
clearInterval(interval);
interval = null;
tens = "00";
seconds = "00";
mint = "00";
hour = "00";
getSeconds.innerHTML = seconds;
getTens.innerHTML = tens;
getMint.innerHTML = mint;
getHour.innerHTML = hour;
});
function startTimer() {
tens++;
if (tens <= 9) {
getTens.innerHTML = "0" + tens;
}
if (tens > 9) {
getTens.innerHTML = tens;
}
if (tens > 99) {
seconds++;
getSeconds.innerHTML = "0" + seconds;
tens = 0;
getTens.innerHTML = "0" + 0;
}
if (seconds > 9) {
getSeconds.innerHTML = seconds;
}
if (seconds > 60) {
mint++;
getMint.innerHTML = "0" + mint;
seconds = 0;
getSeconds.innerHTML = "0" + 0
}
if (mint > 99) {
getMint.innerHTML = mint;
}
}