-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (38 loc) · 761 Bytes
/
index.js
File metadata and controls
44 lines (38 loc) · 761 Bytes
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
let hour = 00;
let min = 00;
let sec = 00;
let interval;
const watch = document.querySelector('.watch');
const start = () => {
isRunning();
interval = setInterval(isRunning, 1000); // 1 second
}
const pause = () => {
clearInterval(interval);
}
const stop = () => {
clearInterval(interval);
hour = 00;
min = 00;
sec = 00;
watch.innerHTML = `00:00:00`;
}
const twoZeros = (digit) => {
if (digit < 10) {
return '0' + digit;
} else {
return digit;
}
}
const isRunning = () => {
sec++
watch.innerHTML = `${twoZeros(hour)}:${twoZeros(min)}:${twoZeros(sec)}`;
if (sec > 59) {
min++
sec = 00;
if (min > 59) {
hour++
min = 0;
}
}
}