Skip to content

Commit fbc7a56

Browse files
committed
refactor: extract display update logic into separate function
1 parent 8f1a667 commit fbc7a56

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@ function formatTime(totalSeconds) {
2323
*/
2424
function updateTime() {
2525
timeRemainingInSeconds = timeRemainingInSeconds - 1;
26-
titleElement.innerText = formatTime(timeRemainingInSeconds);
26+
displayTime();
2727

2828
if (timeRemainingInSeconds === 0) {
2929
playAlarm();
3030
document.body.classList.add("flash");
3131
clearInterval(alarmTimerIdentifier);
32-
alarmTimerIdentifier = null; // ← reset to null for proper state management
32+
alarmTimerIdentifier = null; // Reset to null for proper state management
3333
}
3434
}
3535

36+
/**
37+
* Displays the remaining time.
38+
*/
39+
function displayTime() {
40+
const titleElement = document.getElementById("timeRemaining");
41+
titleElement.innerText = formatTime(timeRemainingInSeconds);
42+
}
43+
3644
/**
3745
* Initialises the alarm countdown.
3846
*/
@@ -59,7 +67,7 @@ function setAlarm() {
5967
audio.play();
6068
audio.pause();
6169

62-
titleElement.innerText = formatTime(timeRemainingInSeconds);
70+
displayTime();
6371

6472
alarmTimerIdentifier = setInterval(() => {
6573
updateTime();

0 commit comments

Comments
 (0)