-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.js
39 lines (32 loc) · 1.03 KB
/
Timer.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
let time = 60;
let displayMinutes = Math.floor(time/60);
let displaySeconds = time % 60;
let interval = null
let status = "stopped"
function startStop(){
if (status === "stopped") {
interval = window.setInterval(timer, 1000);
document.getElementById("startStop").innerHTML = "Stop"
status = "started";}
else{
window.clearInterval(interval);
document.getElementById("startStop").innerHTML = "Start";
status = "stopped";
}
}
function timer(){
time--;
let displayMinutes = Math.floor(time/60);
let displaySeconds = time % 60;
displaySeconds < 10 ? displaySeconds = "0" + displaySeconds : displaySeconds
document.getElementById("timer").innerHTML = `${displayMinutes}: ${displaySeconds}`;
if (time == 0) {
clearInterval(interval);
}
}
function reset(){
clearInterval(interval);
time = 60;
displaySeconds < 10 ? displaySeconds = "0" + displaySeconds : displaySeconds
document.getElementById("timer").innerHTML = `${displayMinutes}: ${displaySeconds}`;
}