-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (37 loc) · 1.07 KB
/
script.js
File metadata and controls
43 lines (37 loc) · 1.07 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
let timerDisplay = document.querySelector(".timerDisplay");
let stopBtn = document.getElementById("stopBtn");
let startBtn = document.getElementById("startBtn");
let resetBtn = document.getElementById("resetBtn");
let msec = 0o0;
let secs = 0o0;
let mins = 0o0;
let timerid = null;
startBtn.addEventListener("click",function(){
if(timerid !==null){
clearInterval(timerid);
}
timerid= setInterval(startTimer,10);
});
stopBtn.addEventListener("click",function(){
clearInterval(timerid);
});
resetBtn.addEventListener("click",function(){
clearInterval(timerid);
timerDisplay.innerHTML = `00 : 00 : 00`
})
function startTimer(){
msec++;
if(msec==100){
msec=0;
secs++;
if(secs==60){
secs=0;
mins++
}
}
let msecString = msec < 10 ? `0${msec}`: msec;
let secsString = secs < 10 ? `0${secs}` : secs;
let minsString = mins < 10 ? `0${mins}` : mins;
timerDisplay.innerHTML = `${minsString} :
${secsString}: ${msecString}`;
}