-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstopwatch.js
More file actions
79 lines (65 loc) · 1.54 KB
/
stopwatch.js
File metadata and controls
79 lines (65 loc) · 1.54 KB
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
78
79
let stopwatch = document.getElementById("stopwatch")
let startButton = document.getElementById("start")
var stopTime = document.getElementById("stoptime")
let timeOut = null
let mili = 0
let sec = 0
let min = 0
function start() {
// if (flag) {
startButton.disabled = true
// }
timeOut = setTimeout(function () {
mili = parseInt(mili)
sec = parseInt(sec)
min = parseInt(min)
mili++;
if (mili == 100) {
sec = sec + 1
mili = 0;
}
if (sec == 60) {
min = min + 1
sec = 0
}
if (mili < 10) {
mili = '0' + mili
}
if (sec < 10) {
sec = '0' + sec
}
if (min < 10) {
min = '0' + min
}
stopwatch.innerHTML = min + ':' + sec + ':' + mili;
start();
}, 10);
}
let n = 0
function stop() {
clearTimeout(timeOut);
startButton.disabled = false;
n++
let storeTime = min + ':' + sec + ':' + mili
if (storeTime == "0:0:0") {
storeTime = " (" + n + ") " + "00" + ':' + "00" + ':' + "00"
}
else {
storeTime = " (" + n + ") " + min + ':' + sec + ':' + mili;
}
let p = document.createElement("p")
stopTime.append(p)
p.append(storeTime)
p.style.fontSize ="50px"
p.style.fontWeight ="bolder"
}
function reset() {
mili = 0;
sec = 0;
min = 0;
clearTimeout(timeOut);
stopwatch.innerHTML = '00:00:00';
stopTime.innerHTML = ""
startButton.disabled = false;
n = 0
}