Skip to content

Commit 3a4bb35

Browse files
Create a newfunction startCountdown and remove the duplicated code
1 parent a940501 commit 3a4bb35

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ function setAlarm() {
2222
}
2323

2424
// Start a new countdown
25+
startCountdown();
26+
}
27+
28+
function startCountdown(){
2529
intervalId = setInterval(() => {
2630
timeRemaining--;
2731
updateDisplay(timeRemaining);
2832

2933
if (timeRemaining <= 0) {
3034
clearInterval(intervalId);
3135
playAlarm();
32-
document.body.classList.add("flash");
36+
document.body.classList.add("flash");
3337
}
3438
}, 1000);
39+
3540
}
3641

3742
function updateDisplay(seconds) {
@@ -49,16 +54,7 @@ function togglePause() {
4954
isPaused = true;
5055
} else {
5156
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);
57+
startCountdown();
6258
}
6359
}
6460

0 commit comments

Comments
 (0)