From debc32759c497088e387ad8490d9a64242451461 Mon Sep 17 00:00:00 2001 From: Mouawia Elkhalifa Date: Tue, 24 Mar 2026 14:22:16 +0000 Subject: [PATCH 1/3] Complete alarm clock --- Sprint-3/alarmclock/alarmclock.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..488c199db 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,30 @@ -function setAlarm() {} +function setAlarm() { + let timeRemaining = document.getElementById("alarmSet").value; + const timeDisplay = document.getElementById("timeRemaining"); + + // Create a reusable function to update the text on the screen + const updateDisplay = (time) => { + let minutes = Math.floor(time / 60) + .toString() + .padStart(2, "0"); + let seconds = (time % 60).toString().padStart(2, "0"); + timeDisplay.innerText = "Time Remaining: " + minutes + ":" + seconds; + }; + + // STEP 1: Display the starting time IMMEDIATELY + updateDisplay(timeRemaining); + + // STEP 2: Start the interval + const countdown = setInterval(() => { + timeRemaining--; + updateDisplay(timeRemaining); + + if (timeRemaining <= 0) { + clearInterval(countdown); + playAlarm(); + } + }, 1000); +} // DO NOT EDIT BELOW HERE From 0614dd3be9edd9aaba49eb895f536f1fe5a7c5e1 Mon Sep 17 00:00:00 2001 From: Mouawia Elkhalifa Date: Sun, 5 Apr 2026 17:26:24 +0100 Subject: [PATCH 2/3] temp fix for alarm clock --- Sprint-3/alarmclock/alarmclock.js | 49 ++++++++++++++++++------------- Sprint-3/alarmclock/index.html | 2 +- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 488c199db..7e6ed5823 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,29 +1,36 @@ +let countdown = null; + function setAlarm() { - let timeRemaining = document.getElementById("alarmSet").value; - const timeDisplay = document.getElementById("timeRemaining"); - - // Create a reusable function to update the text on the screen - const updateDisplay = (time) => { - let minutes = Math.floor(time / 60) - .toString() - .padStart(2, "0"); - let seconds = (time % 60).toString().padStart(2, "0"); - timeDisplay.innerText = "Time Remaining: " + minutes + ":" + seconds; + let secondsLeft = parseInt(document.getElementById("alarmSet").value, 10); + const timeDisplay = document.getElementById("timeRemaining"); + + if (isNaN(secondsLeft) || secondsLeft <= 0) { + timeDisplay.innerText = "Time Remaining: 00:00"; + return; + } + + if (countdown !== null) { + clearInterval(countdown); + } + + const updateDisplay = (time) => { + let minutes = Math.floor(time / 60).toString().padStart(2, "0"); + let seconds = (time % 60).toString().padStart(2, "0"); + timeDisplay.innerText = "Time Remaining: " + minutes + ":" + seconds; }; - // STEP 1: Display the starting time IMMEDIATELY - updateDisplay(timeRemaining); + updateDisplay(secondsLeft); - // STEP 2: Start the interval - const countdown = setInterval(() => { - timeRemaining--; - updateDisplay(timeRemaining); + countdown = setInterval(() => { + secondsLeft = secondsLeft - 1; + updateDisplay(secondsLeft); - if (timeRemaining <= 0) { - clearInterval(countdown); - playAlarm(); + if (secondsLeft <= 0) { + clearInterval(countdown); + countdown = null; + playAlarm(); } - }, 1000); + }, 1000); } // DO NOT EDIT BELOW HERE @@ -48,4 +55,4 @@ function pauseAlarm() { audio.pause(); } -window.onload = setup; +window.onload = setup; \ No newline at end of file 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 c171be8b6b193fdcaf70b60c0ff013d5896007cd Mon Sep 17 00:00:00 2001 From: Mouawia Elkhalifa Date: Mon, 6 Apr 2026 12:25:27 +0100 Subject: [PATCH 3/3] fix: address reviewer feedback for reset and stop logic --- Sprint-3/alarmclock/alarmclock.js | 66 ++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 7e6ed5823..394864b7b 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,36 +1,47 @@ -let countdown = null; +let countdown = null; -function setAlarm() { - let secondsLeft = parseInt(document.getElementById("alarmSet").value, 10); - const timeDisplay = document.getElementById("timeRemaining"); - - if (isNaN(secondsLeft) || secondsLeft <= 0) { - timeDisplay.innerText = "Time Remaining: 00:00"; - return; - } +function updateDisplay(time) { + const timeDisplay = document.getElementById("timeRemaining"); + let minutes = Math.floor(time / 60) + .toString() + .padStart(2, "0"); + let seconds = (time % 60).toString().padStart(2, "0"); + timeDisplay.innerText = "Time Remaining: " + minutes + ":" + seconds; +} - if (countdown !== null) { +function resetAlarm() { + if (countdown !== null) { clearInterval(countdown); + countdown = null; } - const updateDisplay = (time) => { - let minutes = Math.floor(time / 60).toString().padStart(2, "0"); - let seconds = (time % 60).toString().padStart(2, "0"); - timeDisplay.innerText = "Time Remaining: " + minutes + ":" + seconds; - }; + pauseAlarm(); + audio.currentTime = 0; + updateDisplay(0); +} + +function setAlarm() { + resetAlarm(); + + let secondsLeft = parseInt(document.getElementById("alarmSet").value, 10); + + if (isNaN(secondsLeft) || secondsLeft <= 0) { + updateDisplay(0); + return; + } - updateDisplay(secondsLeft); + updateDisplay(secondsLeft); - countdown = setInterval(() => { - secondsLeft = secondsLeft - 1; - updateDisplay(secondsLeft); + countdown = setInterval(() => { + secondsLeft = secondsLeft - 1; + updateDisplay(secondsLeft); - if (secondsLeft <= 0) { - clearInterval(countdown); - countdown = null; - playAlarm(); + if (secondsLeft <= 0) { + clearInterval(countdown); + countdown = null; + playAlarm(); } - }, 1000); + }, 1000); } // DO NOT EDIT BELOW HERE @@ -45,6 +56,13 @@ function setup() { document.getElementById("stop").addEventListener("click", () => { pauseAlarm(); }); + + document.getElementById("stop").addEventListener("click", () => { + if (countdown !== null) { + clearInterval(countdown); + countdown = null; + } + }); } function playAlarm() {