Skip to content

Commit b2b7638

Browse files
created a function to toggle and pause
1 parent 0496416 commit b2b7638

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ function updateDisplay(seconds) {
4343

4444
title.textContent = `Time Remaining: ${mins}:${secs}`;
4545
}
46+
function togglePause() {
47+
if (!isPaused) {
48+
clearInterval(intervalId);
49+
isPaused = true;
50+
} else {
51+
isPaused = false;
52+
intervalId = setInterval(() => {
53+
timeRemaining--;
54+
updateDisplay(timeRemaining);
55+
56+
if (timeRemaining <= 0) {
57+
clearInterval(intervalId);
58+
playAlarm();
59+
document.body.classList.add("flash");
60+
}
61+
}, 1000);
62+
}
63+
}
64+
4665

4766
document.getElementById("stop").addEventListener("click", () => {
4867
document.body.classList.remove("flash");

0 commit comments

Comments
 (0)