Skip to content

Commit 6cb11f7

Browse files
author
Pretty Taruvinga
committed
Fix alarm clock timer logic and display update"
1 parent 9fdb334 commit 6cb11f7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ function formatTime(seconds) {
77
return `${mins}:${secs}`;
88
}
99

10+
function updateDisplay(timeLeft) {
11+
const display = document.getElementById("timeRemaining");
12+
display.textContent = `Time Remaining: ${formatTime(timeLeft)}`;
13+
}
14+
1015
function setAlarm() {
1116
const input = document.getElementById("alarmSet").value;
12-
const display = document.getElementById("timeRemaining");
1317

1418
timeLeft = parseInt(input, 10);
1519

@@ -18,15 +22,16 @@ function setAlarm() {
1822
return;
1923
}
2024

21-
display.textContent = `Time Remaining: ${formatTime(timeLeft)}`;
22-
2325
if (timer) {
2426
clearInterval(timer);
2527
}
28+
29+
updateDisplay(timeLeft);
30+
2631
timer = setInterval(() => {
2732
if (timeLeft > 0) {
2833
timeLeft--;
29-
display.textContent = `Time Remaining: ${formatTime(timeLeft)}`;
34+
updateDisplay(timeLeft);
3035
} else {
3136
clearInterval(timer);
3237
playAlarm();

0 commit comments

Comments
 (0)