-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
36 lines (32 loc) · 983 Bytes
/
Copy pathtimer.js
File metadata and controls
36 lines (32 loc) · 983 Bytes
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
const start = document.querySelector('#start');
const reset = document.querySelector('#reset');
const h = document.querySelector('#hour');
const m = document.querySelector('#minute');
const s = document.querySelector('#second');
let interval = null;
function stopInterval() {
clearInterval(interval);
}
start.addEventListener('click',()=>{
interval = setInterval(()=> {
if(s.value != 0) {
s.value -= 1;
} else if(m.value != 0 && s.value == 0) {
s.value = 59;
m.value -= 1;
} else if(h.value != 0 && m.value == 0) {
m.value = 59;
h.value -= 1;
}
if(h.value == 0 && m.value == 0 && s.value == 0) {
alert(`time up`);
stopInterval();
}
}, 1000);
});
reset.addEventListener('click',()=>{
h.value = " ";
m.value = " ";
s.value = " ";
stopInterval();
});