-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopwatch.js
52 lines (43 loc) · 1.18 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
window.onload = function () {
let seconds = 00;
let milis = 00;
let appendMilis = document.getElementById("milis");
let appendSeconds = document.getElementById("seconds");
let buttonStart = document.getElementById("button-start");
let buttonStop = document.getElementById("button-stop");
let buttonReset = document.getElementById("button-reset");
let Interval ;
buttonStart.onclick = function() {
clearInterval(Interval);
Interval = setInterval(startTimer, 10);
}
buttonStop.onclick = function() {
clearInterval(Interval);
}
buttonReset.onclick = function() {
clearInterval(Interval);
milis = "00";
seconds = "00";
appendMilis.innerHTML = milis;
appendSeconds.innerHTML = seconds;
}
function startTimer() {
milis++;
if(milis <= 9) {
appendMilis.innerHTML = "0" + milis;
}
if(milis >= 9) {
appendMilis.innerHTML = milis;
}
if(milis > 99) {
console.log("seconds");
seconds++;
appendSeconds.innerHTML = "0" + seconds;
milis = 0;
appendMilis.innerHTML = "0" + 0;
}
if(seconds > 9) {
appendSeconds.innerHTML = seconds;
}
}
}