-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTOP.js
77 lines (63 loc) · 1.75 KB
/
STOP.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
67
68
69
70
71
72
73
74
75
76
77
let startBtn = document.getElementById('start');
let stopBtn = document.getElementById('stop');
let resetBtn = document.getElementById('reset');
let hour = 00;
let minute = 00;
let second = 00;
let count = 00;
startBtn.addEventListener('click', function () {
timer = true;
stopWatch();
});
stopBtn.addEventListener('click', function () {
timer = false;
});
resetBtn.addEventListener('click', function () {
timer = false;
hour = 0;
minute = 0;
second = 0;
count = 0;
document.getElementById('hr').innerHTML = "00";
document.getElementById('min').innerHTML = "00";
document.getElementById('sec').innerHTML = "00";
document.getElementById('count').innerHTML = "00";
});
function stopWatch() {
if (timer) {
count++;
if (count == 100) {
second++;
count = 0;
}
if (second == 60) {
minute++;
second = 0;
}
if (minute == 60) {
hour++;
minute = 0;
second = 0;
}
let hrString = hour;
let minString = minute;
let secString = second;
let countString = count;
if (hour < 10) {
hrString = "0" + hrString;
}
if (minute < 10) {
minString = "0" + minString;
}
if (second < 10) {
secString = "0" + secString;
}
if (count < 10) {
countString = "0" + countString;
}
document.getElementById('hr').innerHTML = hrString;
document.getElementById('min').innerHTML = minString;
document.getElementById('sec').innerHTML = secString;
document.getElementById('count').innerHTML = countString;
setTimeout(stopWatch, 10);
}}