-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (53 loc) · 1.42 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let seconds = 00;
let tens = 00;
let mins = 00;
let getSeconds = document.querySelector('.seconds');
let getTens = document.querySelector('.tens');
let getMins = document.querySelector('.mins');
let btnStart = document.querySelector('.btn-start');
let btnStop = document.querySelector('.btn-stop');
let btnReset = document.querySelector('.btn-reset');
let interval;
btnStart.addEventListener('click', () => {
clearInterval(interval);
inverval = setInterval(startTimer, 10);
})
btnStop.addEventListener('click', () => {
clearInterval(inverval);
})
btnReset.addEventListener('click', () => {
clearInterval(inverval);
tens = '00';
seconds = '00';
mins = '00';
getSeconds.innerHTML = seconds;
getTens.innerHTML = tens;
getMins.innerHTML = mins;
})
function startTimer(){
tens++;
if(tens <= 9){
getTens.innerHTML = '0' + tens;
}
if(tens > 9){
getTens.innerHTML = tens;
}
if(tens > 99){
seconds++;
getSeconds.innerHTML = '0' + seconds;
tens = 0;
getTens.innerHTML = '0' + 0;
}
if(seconds > 9){
getSeconds.innerHTML = seconds;
}
if(seconds > 59){
mins++;
getMins.innerHTML = '0' + mins;
seconds = 0;
getSeconds.innerHTML = '0' + 0;
}
if(mins > 9){
getSeconds.innerHTML = mins;
}
}