-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (38 loc) · 1.14 KB
/
script.js
File metadata and controls
54 lines (38 loc) · 1.14 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
48
49
50
51
52
53
54
const timer = document.getElementById("timer");
const start = document.getElementById("start");
const stop = document.getElementById("stop");
const reset = document.getElementById("reset");
let interval;
let timeLeft = 1500;
const timerFunc = () => {
let minutes = Math.floor(timeLeft / 60);
let seconds = timeLeft % 60;
let formattedTime = `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
timer.innerHTML = formattedTime;
}
start.addEventListener("click", () => {
start.disabled = true;
start.classList.add("disabled")
interval = setInterval(() => {
timeLeft--;
timerFunc();
if(timeLeft === 0) {
clearInterval(interval);
alert("Time for some break");
timeLeft = 1500;
timerFunc();
}
}, 1000)
})
stop.addEventListener("click", () => {
start.classList.remove("disabled")
clearInterval(interval)
start.disabled = false;
})
reset.addEventListener("click", () => {
clearInterval(interval);
start.disabled = false;
start.classList.remove("disabled")
timeLeft = 1500;
timerFunc();
})