-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextra.js
More file actions
47 lines (41 loc) · 1.34 KB
/
extra.js
File metadata and controls
47 lines (41 loc) · 1.34 KB
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
window.onload = function(){
const hourinput = document.querySelector("#hour");
const minuteinput = document.querySelector("#minute");
const secondinput = document.querySelector("#second");
const millisecondinput = document.querySelector("#millisecond");
const pausetbtn = document.querySelector("#stoptwatch-pause-button-id");
const resetbtn = document.querySelector("#stoptwatch-reset-button-id");
const startbtn = document.querySelector("#stoptwatch-start-button-id");
let hr = 0, m = 0, s =0, watch;
startbtn.addEventListener('click', ()=>{
watch = setInterval( ()=>{
s +=1;
if(s == 60){
m = m +1;
s = 00;
}
if(m == 60){
h = h+1;
m = 00;
}
hourinput.innerText = h;
minuteinput.innerText = m;
secondinput.innerText = s;
millisecondinput.innerText = ms;
},1000);
});
pausetbtn.addEventListener('click',()=>{
clearInterval(watch);
});
resetbtn.addEventListener('click',()=>{
clearInterval(watch);
h = 0;
m = 0;
s = 0;
ms = 0;
hour.innerText = '00';
minute.innerText = '00';
second.innerText = '00';
millisecond.innerText = '00';
});
}