-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
43 lines (34 loc) · 1.08 KB
/
main.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
let timeseconds=10;
const timer = document.getElementById('countdown_clock');
var CountDown;
// Pause or continue the Countdown Clock
let btn = document.getElementById("play");
var clicked = false;
function toggle() {
if (clicked == false) {
clicked=true
btn.innerHTML="Pause"
clearInterval(CountDown);
//countdown our timer
CountDown = setInterval (()=>{
timeseconds--;
DisplayTime(timeseconds);
if(timeseconds <=0 || timeseconds<1){
clearInterval(CountDown);
}
},1000);
function DisplayTime(second) {
const min = Math.floor(second / 60);
const sec = Math.floor(second % 60);
timer.innerHTML = `
${min < 10 ? "0" : ""}${min}:${sec < 10 ? "0" : ""}${sec}
`;
};
} else {
clicked=false;
btn.innerHTML="Play";
if(timeseconds <=0 || timeseconds<1){
clearInterval(CountDown);
}
}
}