Skip to content

Commit aa73c2b

Browse files
committed
alarm sound resets
1 parent d48ff25 commit aa73c2b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ function incrementTime(amount) {
3030
updateDisplay();
3131
}
3232

33+
function resetAlarmState() {
34+
if (timer) clearInterval(timer);
35+
timer = null;
36+
37+
audio.pause();
38+
audio.currentTime = 0;
39+
}
40+
3341
function setAlarm() {
42+
resetAlarmState();
3443
const input = document.getElementById("alarmSet");
3544
const parsed = parseInputTime(input.value);
3645

@@ -66,7 +75,9 @@ function stopTimer() {
6675
}
6776

6877
document.getElementById("up").addEventListener("click", () => incrementTime(5));
69-
document.getElementById("down").addEventListener("click", () => incrementTime(-5));
78+
document
79+
.getElementById("down")
80+
.addEventListener("click", () => incrementTime(-5));
7081
document.getElementById("set").addEventListener("click", setAlarm);
7182
document.getElementById("stop").addEventListener("click", stopTimer);
7283

0 commit comments

Comments
 (0)