-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
54 lines (45 loc) · 1.19 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
let ms = document.querySelector("#milliSeconds");
let sec = document.querySelector("#seconds");
let minutes = document.querySelector("#minutes");
const init = document.querySelector("#init");
const pause = document.querySelector("#pause");
const clear = document.querySelector("#clear");
let cron
function timer() {
ms.textContent++
format(ms)
if (ms.textContent > 99) {
ms.textContent = 0;
sec.textContent++;
format(sec);
format(ms);
}
if (sec.textContent > 59) {
sec.textContent = 0;
minutes.textContent++;
format(sec);
format(minutes);
}
if (minutes > 59) {
clearInterval(timer);
}
}
function format(e) {
e.textContent < 10 ? e.textContent = `0${e.textContent}` : e.textContent;
}
init.addEventListener("click", () => {
pauseF();
cron = setInterval(timer, 10);
})
function pauseF() {
clearInterval(cron);
}
pause.addEventListener("click", () => {
pauseF();
})
clear.addEventListener("click",()=>{
pauseF();
document.querySelectorAll("#milliSeconds,#seconds,#minutes").forEach(e=>{
e.textContent = "00"
})
})