-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (37 loc) · 1.17 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
48
window.onload = function () {
let seconds = 0;
let tens = 0;
let buttonStart = document.querySelector('#button-start');
let buttonStop = document.querySelector('#button-stop');
let buttonReset = document.querySelector('#button-reset');
let appendSeconds = document.querySelector('#seconds');
let appendTens = document.querySelector('#tens')
let interval;
buttonStart.onclick = () => {
this.clearInterval(interval);
interval = setInterval(startTimer, 10);
}
buttonStop.onclick = ()=>{
this.clearInterval(interval);
}
buttonReset.onclick = ()=> {
this.clearInterval(interval);
tens = "00"
seconds = "00";
appendTens.innerHTML = tens;
appendSeconds.innerHTML = seconds;
}
function startTimer() {
tens++;
tens < 9 ? appendTens.innerHTML = '0'+ tens : appendTens.innerHTML = tens;
if(tens > 99){
seconds++;
appendSeconds.innerHTML = '0' + seconds;
tens = 0;
appendTens.innerHTML = '0' + 0;
}
if(seconds > 9){
appendSeconds.innerHTML = seconds;
}
}
}