From 507a1a6b1520c90cb2c048eca9d47342e2304965 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 28 Jul 2026 00:37:15 +0100 Subject: [PATCH 1/6] Implement setAlarm function to parse input value and handle invalid or empty inputs --- Sprint-3/alarmclock/alarmclock.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..fa3dcc1fa 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,16 @@ -function setAlarm() {} +let timerInterval = null; + +function setAlarm() { + const inputEl = document.getElementById("alarmSet"); + const timeRemainingEl = document.getElementById("timeRemaining"); + + let totalSeconds = parseInt(inputEl.value, 10); + + // If input is invalid or empty, default to 0 + if (isNaN(totalSeconds) || totalSeconds < 0) { + totalSeconds = 0; + } +} // DO NOT EDIT BELOW HERE From d5cfd5bc4a4d4271fb51dcbb58a7469631ee3478 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 28 Jul 2026 00:38:42 +0100 Subject: [PATCH 2/6] Add timer clearing logic to setAlarm function for repeated button clicks --- Sprint-3/alarmclock/alarmclock.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index fa3dcc1fa..40e87b5fd 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -10,6 +10,10 @@ function setAlarm() { if (isNaN(totalSeconds) || totalSeconds < 0) { totalSeconds = 0; } + // Clear any existing timer if the button is clicked again + if (timerInterval) { + clearInterval(timerInterval); + } } // DO NOT EDIT BELOW HERE From 54ce6875e6b56b51bd70a06a326671625d722352 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 28 Jul 2026 00:39:21 +0100 Subject: [PATCH 3/6] Refactor setAlarm function to improve countdown timer logic and ensure immediate display update on button click --- Sprint-3/alarmclock/alarmclock.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 40e87b5fd..f3baee3de 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -14,6 +14,32 @@ function setAlarm() { if (timerInterval) { clearInterval(timerInterval); } + // Function to render the formatted time (MM:SS) to the DOM + function updateDisplay() { + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + + const formattedMinutes = String(minutes).padStart(2, "0"); + const formattedSeconds = String(seconds).padStart(2, "0"); + + timeRemainingEl.innerText = `Time Remaining: ${formattedMinutes}:${formattedSeconds}`; + } + // 1. Immediately set heading on button click + updateDisplay(); + + // 2. Start the countdown timer + timerInterval = setInterval(() => { + totalSeconds -= 1; + + if (totalSeconds >= 0) { + updateDisplay(); + } + + if (totalSeconds === 0) { + playAlarm(); + clearInterval(timerInterval); + } + }, 1000); } // DO NOT EDIT BELOW HERE From a20ef05766acc521e769c63759b36f1415ba61ed Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 31 Jul 2026 03:13:53 +0100 Subject: [PATCH 4/6] Fix setAlarm function to return early for invalid or empty input values --- Sprint-3/alarmclock/alarmclock.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index f3baee3de..b62dc41f9 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -7,8 +7,8 @@ function setAlarm() { let totalSeconds = parseInt(inputEl.value, 10); // If input is invalid or empty, default to 0 - if (isNaN(totalSeconds) || totalSeconds < 0) { - totalSeconds = 0; + if (isNaN(totalSeconds) || totalSeconds <= 0) { + return; } // Clear any existing timer if the button is clicked again if (timerInterval) { From f6577e75ac3311f1b17eb17511a12b1de620adc8 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 31 Jul 2026 03:17:41 +0100 Subject: [PATCH 5/6] Fix HTML structure and update title for Alarm Clock App --- Sprint-3/alarmclock/index.html | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..409de67ec 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,20 +1,23 @@ - - - - - Title here - - -
-

Time Remaining: 00:00

- - - - -
- - - + + + + + Alarm Clock App + + + +
+

Time Remaining: 00:00

+ + + + + +
+ + + + \ No newline at end of file From d61207f60ddbe844bf3759c8adb2dfc1611fd241 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Sun, 2 Aug 2026 08:42:42 +0100 Subject: [PATCH 6/6] Fix setAlarm function to handle invalid input and added a error message as user feedback --- Sprint-3/alarmclock/alarmclock.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index b62dc41f9..995e25a12 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -8,6 +8,8 @@ function setAlarm() { // If input is invalid or empty, default to 0 if (isNaN(totalSeconds) || totalSeconds <= 0) { + if (timerInterval) clearInterval(timerInterval); // Stop any running timer + timeRemainingEl.innerText = "Please enter a valid time (greater than 0)"; // Inform the user return; } // Clear any existing timer if the button is clicked again