-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (41 loc) · 937 Bytes
/
app.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
let [seconds, minutes, hours] = [0, 0, 0];
let displayTime = document.getElementById("displayTime");
let timer = null;
function stoptWatch() {
seconds++;
if (seconds == 60) {
seconds = 0;
minutes++;
if (minutes == 60) {
minutes = 0;
hours++;
}
if (hours == 12) {
hours = 0;
}
}
let h = hours < 10 ? "0" + hours : hours;
let m = minutes < 10 ? "0" + minutes : minutes;
let s = seconds < 10 ? "0" + seconds : seconds;
displayTime.innerHTML = h + ":" + m + ":" + s;
}
function watchStart() {
if (timer !== null) {
clearInterval(timer);
}
timer = setInterval(stoptWatch, 1000);
}
function watchStop() {
clearInterval(timer);
console.log(seconds, minutes, hours);
}
function watchReset() {
if (timer !== null) {
clearInterval(timer);
}
seconds = 0;
minutes = 0;
hours = 0;
displayTime.innerHTML = "00:00:00";
console.log(seconds, minutes, hours);
}