-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathscript.js
47 lines (42 loc) · 1.07 KB
/
script.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
let sec = '00';
let millisec = '00';
let appendsec = document.querySelector('.sec');
let appendmillisec = document.querySelector('.millisec');
let buttonStart = document.querySelector('.start');
let buttonStop = document.querySelector('.stop');
let buttonReset = document.querySelector('.reset');
let interval;
function startTimer() {
millisec++;
if(millisec<=9){
appendmillisec.innerHTML = '0' + millisec;
}
if(millisec>9){
appendmillisec.innerHTML = millisec;
}
if(millisec>99){
sec++;
appendsec.innerHTML = '0' + sec;
millisec = 0;
appendmillisec.innerHTML = '0' + 0;
}
if(sec>9){
appendsec.innerHTML = sec;
}
}
buttonStart.onclick = function() {
if(interval) {
clearInterval(interval);
}
interval = setInterval(startTimer, 10);
};
buttonStop.onclick = function() {
clearInterval(interval);
};
buttonReset.onclick = function() {
clearInterval(interval);
millisec = '00';
sec = '00';
appendmillisec.innerHTML = millisec;
appendsec.innerHTML = sec;
};