From 3a34f9ffbd66a743ef9ba084e0fbe6d151780660 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 14 Jul 2025 10:35:44 +0100 Subject: [PATCH 01/18] updated title name placeholder to Alarm clock app --- 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..4a91379d3 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock App
From 0289a03513b203e2d309138470bd846497a79cae Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 14 Jul 2025 11:16:37 +0100 Subject: [PATCH 02/18] implemented: selects the users input field from the DOM to retrieve set alarm value --- Sprint-3/alarmclock/alarmclock.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..6acc9d588 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,7 @@ -function setAlarm() {} +function setAlarm() { + // get the users input in seconds from the input element + const inputField = document.getElementById("alarmSet") +} // DO NOT EDIT BELOW HERE From b3fb326b00fcdefef24cb05786315a6b41be310a Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 14 Jul 2025 11:31:38 +0100 Subject: [PATCH 03/18] implemented: Select DOM element that displays the remaining time for the countdown --- Sprint-3/alarmclock/alarmclock.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6acc9d588..ce8f5f3a7 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,6 +1,9 @@ function setAlarm() { // get the users input in seconds from the input element const inputField = document.getElementById("alarmSet") + + // get the "timeRemaining" element where we show the time + const timeDisplay = document.getElementById("timeRemaining") } // DO NOT EDIT BELOW HERE From 192cceec037201f8f573bf8b5d819caa8fea1a1b Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 14 Jul 2025 12:30:21 +0100 Subject: [PATCH 04/18] implemented: convert user input into a number --- Sprint-3/alarmclock/alarmclock.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index ce8f5f3a7..e1220d6db 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,9 +1,12 @@ function setAlarm() { // get the users input in seconds from the input element - const inputField = document.getElementById("alarmSet") + const inputField = document.getElementById("alarmSet"); // get the "timeRemaining" element where we show the time - const timeDisplay = document.getElementById("timeRemaining") + const timeDisplay = document.getElementById("timeRemaining"); + + // convert the users input to a number + let secondsRemaining = number(inputField.value); } // DO NOT EDIT BELOW HERE From 273cafc4ac0cf710bf76f49cd6f1cb32883f1710 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 14 Jul 2025 12:32:00 +0100 Subject: [PATCH 05/18] fix: correct typo in number conversion for user input --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index e1220d6db..ebdde94c8 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -6,7 +6,7 @@ function setAlarm() { const timeDisplay = document.getElementById("timeRemaining"); // convert the users input to a number - let secondsRemaining = number(inputField.value); + let secondsRemaining = Number(inputField.value); } // DO NOT EDIT BELOW HERE From 5fe19ee5127cf1683051c12d003f30e24da93c62 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 14 Jul 2025 14:02:11 +0100 Subject: [PATCH 06/18] implemented: add function to format and update time display in setAlarm --- Sprint-3/alarmclock/alarmclock.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index ebdde94c8..1666830ec 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -7,6 +7,14 @@ function setAlarm() { // convert the users input to a number let secondsRemaining = Number(inputField.value); + + // format and update the time display with a function + function updatedTime(){ + // calculate the number into minutes and seconds + const minutes = Math.floor(secondsRemaining / 60); + const seconds = secondsRemaining % 60; + + } } // DO NOT EDIT BELOW HERE From 3c31af3d81e837748a9064959a7a4fb6d9dd6cbc Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 14 Jul 2025 15:43:23 +0100 Subject: [PATCH 07/18] added: Ensure countdown timer displays two-digit minutes and seconds using padStart --- 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 1666830ec..29ce43a43 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -14,6 +14,10 @@ function setAlarm() { const minutes = Math.floor(secondsRemaining / 60); const seconds = secondsRemaining % 60; + // pad the numbers to ensure double digits so it looks right and is easily readable + const formattedTime = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`; + timeDisplay.textContext = `Time Remaining: ${formattedTime}`; + } } From 21f33e2325af34c2bed6388fa0e934e851bcf9e5 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 15 Jul 2025 12:02:31 +0100 Subject: [PATCH 08/18] implemented: call updatedTime function to display initial countdown time --- Sprint-3/alarmclock/alarmclock.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 29ce43a43..f4e3a8791 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -19,6 +19,7 @@ function setAlarm() { timeDisplay.textContext = `Time Remaining: ${formattedTime}`; } + updatedTime() // shows the starting time } // DO NOT EDIT BELOW HERE From b0c3c0c1c9e48fd8ebbf58c6b2edc52380ff04fd Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 15 Jul 2025 12:16:54 +0100 Subject: [PATCH 09/18] fix: validate user input for positive number in setAlarm function --- Sprint-3/alarmclock/alarmclock.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index f4e3a8791..13a28a46e 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -8,6 +8,12 @@ function setAlarm() { // convert the users input to a number let secondsRemaining = Number(inputField.value); + // check if input is not a number or less than or equal to zero and informs the user to enter a positive number + if (NaN(secondsRemaining) || secondsRemaining <= 0){ + timeDisplay.textContent = "Enter a positive number."; + return; + } + // format and update the time display with a function function updatedTime(){ // calculate the number into minutes and seconds From f3f61ed4518584bbfb207a84813d31e4d8ed46d4 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 15 Jul 2025 13:22:56 +0100 Subject: [PATCH 10/18] fixed typo error with isNaN --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 13a28a46e..b82af9615 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -9,7 +9,7 @@ function setAlarm() { let secondsRemaining = Number(inputField.value); // check if input is not a number or less than or equal to zero and informs the user to enter a positive number - if (NaN(secondsRemaining) || secondsRemaining <= 0){ + if (isNaN(secondsRemaining) || secondsRemaining <= 0){ timeDisplay.textContent = "Enter a positive number."; return; } From 7b868a298014f31fa863b9248de82dc731277848 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 15 Jul 2025 18:44:07 +0100 Subject: [PATCH 11/18] corrected typo for textContext to textContent --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index b82af9615..978855232 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -22,7 +22,7 @@ function setAlarm() { // pad the numbers to ensure double digits so it looks right and is easily readable const formattedTime = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`; - timeDisplay.textContext = `Time Remaining: ${formattedTime}`; + timeDisplay.textContent = `Time Remaining: ${formattedTime}`; } updatedTime() // shows the starting time From a8fb6fbee245dbf894f21066fff954948ecaff06 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 16 Jul 2025 11:18:50 +0100 Subject: [PATCH 12/18] fix: clear existing interval before starting a new countdown timer and decrementing the timer --- Sprint-3/alarmclock/alarmclock.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 978855232..ac7c90a8a 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -26,6 +26,17 @@ function setAlarm() { } updatedTime() // shows the starting time + + let intervalId; // store a global variable to the interval ID, so we can clear it later + + // if there’s already a running interval clear it to avoid multiple timers + if (intervalId) { + clearInterval(intervalId); + + alarmInterval = setInterval(() => { + // Decrementing the users input seconds by 1 to countdown + secondsRemaining--; + }); } // DO NOT EDIT BELOW HERE From 28b9e82a22adab7ba10dd5ec7e741cb29fbae4c3 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 16 Jul 2025 13:04:40 +0100 Subject: [PATCH 13/18] fix: clear existing interval before starting a new countdown timer and counting down in decrements --- Sprint-3/alarmclock/alarmclock.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index ac7c90a8a..9043db7ec 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -27,16 +27,13 @@ function setAlarm() { } updatedTime() // shows the starting time - let intervalId; // store a global variable to the interval ID, so we can clear it later + let intervalId; // store a global variable to the interval so we can clear it later - // if there’s already a running interval clear it to avoid multiple timers - if (intervalId) { - clearInterval(intervalId); + // Start the countdown interval + intervalId = setInterval(() => { - alarmInterval = setInterval(() => { - // Decrementing the users input seconds by 1 to countdown - secondsRemaining--; - }); + // decrement the number to reduce the countdown + secondsRemaining--; } // DO NOT EDIT BELOW HERE From f958c488f17c6f8e0576c8f4bb6a47e02acf1e82 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 16 Jul 2025 13:09:14 +0100 Subject: [PATCH 14/18] fix: ensure countdown timer clears interval and displays "times up!" when reaching zero --- Sprint-3/alarmclock/alarmclock.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 9043db7ec..92366d5a5 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -34,6 +34,14 @@ function setAlarm() { // decrement the number to reduce the countdown secondsRemaining--; + + // check if the timer has reached 0 + if (secondsRemaining < 0){ + clearInterval(intervalId); // clear the interval when timer reaches 0 + return timeDisplay.textContent = "times up!" // returns times up when + } else { + updatedTime(); + } } // DO NOT EDIT BELOW HERE From e07ee1cd892049444b8ec755caae69b7cbdb63b8 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 16 Jul 2025 13:31:29 +0100 Subject: [PATCH 15/18] fix: clarify return statement for "times up!" message in countdown timer --- Sprint-3/alarmclock/alarmclock.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 92366d5a5..1449ffa88 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -38,9 +38,11 @@ function setAlarm() { // check if the timer has reached 0 if (secondsRemaining < 0){ clearInterval(intervalId); // clear the interval when timer reaches 0 - return timeDisplay.textContent = "times up!" // returns times up when + timeDisplay.textContent = "times up!" // returns times up when timer reaches 0 + return; } else { updatedTime(); + } } } From 92bbd26a2373a11fda7f365c1b625478bdd50b1e Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 16 Jul 2025 13:34:33 +0100 Subject: [PATCH 16/18] fix: correct interval closure in setAlarm function to correctly run function every 1000ms --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 1449ffa88..bcd49a588 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -43,7 +43,7 @@ function setAlarm() { } else { updatedTime(); } - } + }, 1000); } // DO NOT EDIT BELOW HERE From 3c99f1cce6caecc67bddd640ebad2a320ad68409 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 16 Jul 2025 13:41:30 +0100 Subject: [PATCH 17/18] fix: ensure alarm plays when countdown reaches zero --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index bcd49a588..5a618a340 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -39,7 +39,7 @@ function setAlarm() { if (secondsRemaining < 0){ clearInterval(intervalId); // clear the interval when timer reaches 0 timeDisplay.textContent = "times up!" // returns times up when timer reaches 0 - return; + return playAlarm(); } else { updatedTime(); } From 78e82d89cf17d38d5108a38c1165a5bf32f59846 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 16 Jul 2025 14:52:57 +0100 Subject: [PATCH 18/18] fix: add comment to clarify interval update frequency in setAlarm function --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 5a618a340..116378c81 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -43,7 +43,7 @@ function setAlarm() { } else { updatedTime(); } - }, 1000); + }, 1000); // updates the function by running it every 1000ms } // DO NOT EDIT BELOW HERE