-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (67 loc) · 1.72 KB
/
app.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 hour = document.getElementById("hour")
let min =document.getElementById("min")
let sec =document.getElementById("sec")
let msec =document.getElementById("msec")
let startbtn=document.querySelector('.start')
startbtn.disabled=false;
let stopbtn=document.querySelector('.stop')
let resetbtn=document.querySelector('.reset')
let audio=document.getElementById('clockSound')
//timers
let hourTimer=0;
let mintimer=0;
let secTimer=0;
let msecTimer=0;
//startFunc
const startFunc=function(){
msecTimer++;
msec.textContent=msecTimer<10?"0"+ msecTimer :msecTimer;
if(msecTimer===100){
msecTimer=0;
secTimer++;
sec.textContent=secTimer<10?"0"+secTimer+":":secTimer+":";
}
else if(secTimer===60){
secTimer=0;
mintimer++;
min.textContent=mintimer+":";
}
else if(mintimer===60){
mintimer=0;
hourTimer++;
hour.textContent=hourTimer;
}
}
//settingInterval
let startInterval=null;
//Triggerinng Start Event
startbtn.addEventListener('click', function(){
if ( startInterval===null){
audio.play();
startInterval=setInterval(startFunc,10)
startbtn.disabled=true;
}
})
//Triggerinng Stop Event
stopbtn.addEventListener('click', function(){
clearInterval(startInterval);
startInterval=null;
startbtn.disabled=false;
audio.pause()
})
//reset
resetbtn.addEventListener('click', function(){
clearInterval(startInterval);
startInterval=null;
audio.pause()
hour.textContent="00:";
min.textContent="00:";
sec.textContent="00:";
msec.textContent="00";
hourTimer=0;
mintimer=0;
secTimer=0;
msecTimer=0;
startbtn.disabled=false;
})
// ======================================end=======================================