-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopwatch.js
54 lines (42 loc) · 1.53 KB
/
stopwatch.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
window.onload = function () {
var second = "00";
var milli = "00";
var appendSecond = document.getElementById('second');
var appendMilli = document.getElementById('milli');
var buttonstart = document.getElementById('start');
var buttonpause = document.getElementById('pause');
var buttonreset = document.getElementById('reset');
var i;
buttonstart.onclick = function () {
clearInterval(i);
i = setInterval(starttimer, 10);
}
buttonpause.onclick = function () {
clearInterval(i)
}
buttonreset.onclick = function () {
clearInterval(i)
second = "00"
milli = "00"
appendSecond.innerHTML = second;
appendMilli.innerHTML = milli;
}
function starttimer() {
milli++;
if (milli <= 9) {
appendMilli.innerHTML = "0" + milli;
}
if (milli > 9) {
appendMilli.innerHTML = milli;
}
if (milli > 99) {
second++;
appendSecond.innerHTML = "0" + second;
milli = 0;
appendMilli.innerHTML = "0" + 0;
}
}
if (second <= 9) {
appendSecond.innerHTML = second;
}
}