Skip to content

Commit a204333

Browse files
edited js file
1 parent 3eaa8c0 commit a204333

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
var audio = new Audio("alarmsound.mp3");
22

3-
let timeRemaining = 0;
3+
let timeRemaining = 0;
44
let countdownInterval = null;
5-
let hasPlayed = false;
65

76
function setAlarm() {
87
const input = document.getElementById("alarmSet").value;
@@ -14,7 +13,6 @@ function setAlarm() {
1413
return;
1514
}
1615

17-
hasPlayed = false;
1816
updateDisplay();
1917

2018
if (countdownInterval) {
@@ -24,22 +22,14 @@ function setAlarm() {
2422
countdownInterval = setInterval(() => {
2523
timeRemaining--;
2624

27-
// Play alarm at 10 seconds remaining (or immediately if less than 10)
28-
if (!hasPlayed && (timeRemaining === 10 || timeRemaining < 10)) {
29-
playAlarm();
30-
hasPlayed = true;
31-
}
25+
updateDisplay();
3226

3327
if (timeRemaining <= 0) {
34-
timeRemaining = 0;
35-
updateDisplay();
3628
clearInterval(countdownInterval);
37-
return;
29+
playAlarm();
3830
}
39-
40-
updateDisplay();
4131
}, 1000);
42-
} // ✅ properly closed function
32+
}
4333

4434
function updateDisplay() {
4535
const display = document.getElementById("timeRemaining");
@@ -68,4 +58,4 @@ function pauseAlarm() {
6858
}
6959
}
7060

71-
window.onload = setup;
61+
window.onload = setup;

0 commit comments

Comments
 (0)