From fc866d9cc64fca759ca5cbfd0baf11d2acf86955 Mon Sep 17 00:00:00 2001 From: Oussama Mouggal Date: Sat, 21 Mar 2026 14:25:20 +0000 Subject: [PATCH 1/3] changed the title --- Sprint-3/alarmclock/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..ff2d3b453 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
From 7e51a225207e8faff41c1af3adec3dbd7ad49368 Mon Sep 17 00:00:00 2001 From: Oussama Mouggal Date: Sat, 21 Mar 2026 14:26:03 +0000 Subject: [PATCH 2/3] Implement alarm countdown functionality in setAlarm() --- Sprint-3/alarmclock/alarmclock.js | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..043be1831 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,44 @@ -function setAlarm() {} +let countdownTimerId = null; + +function setAlarm() { + const heading = document.getElementById("timeRemaining"); + const input = document.getElementById("alarmSet"); + + let remainingSeconds = Number(input.value); + + if (!Number.isFinite(remainingSeconds) || remainingSeconds < 0) { + remainingSeconds = 0; + } + + remainingSeconds = Math.floor(remainingSeconds); + + if (countdownTimerId !== null) { + clearInterval(countdownTimerId); + } + + const updateHeading = () => { + const minutes = Math.floor(remainingSeconds / 60) + .toString() + .padStart(2, "0"); + const seconds = (remainingSeconds % 60).toString().padStart(2, "0"); + heading.innerText = `Time Remaining: ${minutes}:${seconds}`; + }; + + updateHeading(); + + countdownTimerId = setInterval(() => { + if (remainingSeconds > 0) { + remainingSeconds -= 1; + updateHeading(); + } + + if (remainingSeconds === 0) { + clearInterval(countdownTimerId); + countdownTimerId = null; + playAlarm(); + } + }, 1000); +} // DO NOT EDIT BELOW HERE From 8672e28e7948647c54710b565c2d374c1cf9ee1a Mon Sep 17 00:00:00 2001 From: Oussama Mouggal Date: Wed, 1 Apr 2026 12:13:00 +0100 Subject: [PATCH 3/3] improved alarm functionality --- Sprint-3/alarmclock/alarmclock.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 043be1831..964c6c415 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,17 @@ let countdownTimerId = null; +function resetAlarmState() { + if (countdownTimerId !== null) { + clearInterval(countdownTimerId); + countdownTimerId = null; + } + + // Ensure alarm audio from previous runs is stopped before a new countdown. + if (audio && !audio.paused) { + pauseAlarm(); + } +} + function setAlarm() { const heading = document.getElementById("timeRemaining"); const input = document.getElementById("alarmSet"); @@ -12,9 +24,7 @@ function setAlarm() { remainingSeconds = Math.floor(remainingSeconds); - if (countdownTimerId !== null) { - clearInterval(countdownTimerId); - } + resetAlarmState(); const updateHeading = () => { const minutes = Math.floor(remainingSeconds / 60) @@ -26,6 +36,11 @@ function setAlarm() { updateHeading(); + if (remainingSeconds === 0) { + playAlarm(); + return; + } + countdownTimerId = setInterval(() => { if (remainingSeconds > 0) { remainingSeconds -= 1; @@ -50,7 +65,7 @@ function setup() { }); document.getElementById("stop").addEventListener("click", () => { - pauseAlarm(); + resetAlarmState(); }); }