Skip to content

Commit ffff830

Browse files
author
Ogbemi mene
committed
update of the alarm-app
1 parent b754ede commit ffff830

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
let countdownInterval = null;
2+
23
function setAlarm() {
34
const input = document.getElementById("alarmSet");
45
let totalSeconds = parseInt(input.value, 10);
56

7+
// Return early if input is invalid
68
if (isNaN(totalSeconds) || totalSeconds <= 0) {
79
return;
810
}
911

12+
// 1. Reset Audio: Stop audio if it's currently playing from a previous alarm
13+
pauseAlarm();
14+
audio.currentTime = 0; // Rewind audio track back to the start
15+
16+
// 2. Reset Interval: Clear existing active countdown
1017
if (countdownInterval) {
1118
clearInterval(countdownInterval);
1219
}
@@ -23,17 +30,17 @@ function setAlarm() {
2330
heading.textContent = `Time Remaining: ${formattedMinutes}:${formattedSeconds}`;
2431
}
2532

26-
// Set initial display immediately when button is pressed
2733
updateDisplay(totalSeconds);
2834

29-
// Start 1000ms interval countdown
35+
input.value = "";
36+
3037
countdownInterval = setInterval(() => {
3138
totalSeconds--;
3239
updateDisplay(totalSeconds);
3340

3441
if (totalSeconds <= 0) {
3542
clearInterval(countdownInterval);
36-
playAlarm();
43+
playAlarm();
3744
}
3845
}, 1000);
3946
}

0 commit comments

Comments
 (0)