From 3a1925a480744b66f4270196167a5128652e899c Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 1 Aug 2026 08:59:16 +0100 Subject: [PATCH 01/10] Set up looping alarm --- Sprint-3/alarmclock/alarmclock.js | 28 +++++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 8 ++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..1611f595e 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,30 @@ -function setAlarm() {} +const oneSecondInMilliseconds = 1000; +const lengthOfAlarmSound = 20000; + +function setAlarm() { + // set up time + let now = Date.now(); + let timeLeft = document.getElementById("alarmSet").value; + + // validate result + const result = parseInt(timeLeft); + if (isNaN(result)) { + return; + } + + setTimeout(alarmFinished, timeLeft * oneSecondInMilliseconds); + audio.loop = true; + playAlarm(); +} + +function stopAlarm() { + pauseAlarm(); +} + +function alarmFinished() { + console.log("Alarm finished"); + stopAlarm(); +} // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..77e8f5c77 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,10 +1,10 @@ - + - Title here + Alarm clock app
@@ -12,8 +12,8 @@

Time Remaining: 00:00

- - + +
From d79612d9b4153188470da4b60877df3129172ba4 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 1 Aug 2026 19:08:39 +0100 Subject: [PATCH 02/10] Revert the previous change for index.html --- Sprint-3/alarmclock/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 77e8f5c77..66748001e 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -12,8 +12,8 @@

Time Remaining: 00:00

- - + + From 1e6f60feb69431cea113bbc2e44608e87e5438a6 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 1 Aug 2026 19:09:10 +0100 Subject: [PATCH 03/10] Add setTimout and setInterval --- Sprint-3/alarmclock/alarmclock.js | 61 ++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 1611f595e..4e2a247a0 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,10 +1,20 @@ const oneSecondInMilliseconds = 1000; const lengthOfAlarmSound = 20000; +let timeLeft; +let intervalID; +let timeoutID; +let display; + +// document.getElementById("set").addEventListener("click", setAlarm); +// document.getElementById("stop").addEventListener("click", stopAlarm); + function setAlarm() { + stopAlarm(); + // set up time - let now = Date.now(); - let timeLeft = document.getElementById("alarmSet").value; + timeLeft = document.getElementById("alarmSet").value; + display = document.getElementById("timeRemaining"); // validate result const result = parseInt(timeLeft); @@ -12,18 +22,57 @@ function setAlarm() { return; } - setTimeout(alarmFinished, timeLeft * oneSecondInMilliseconds); - audio.loop = true; - playAlarm(); + display.textContent = formatTime(timeLeft); + + if (!timeoutID) { + timeoutID = setTimeout(alarmFinished, timeLeft * oneSecondInMilliseconds); + } + + if (!intervalID) { + intervalID = setInterval(updateTimer, 1000); + } + + console.log(`Alarm set for ${timeLeft} seconds`); +} + +function updateTimer() { + timeLeft = timeLeft - 1; + + display.textContent = formatTime(timeLeft); + + if (timeLeft <= 0) { + cleanUp(); + } +} + +// give a time in seconds +function formatTime(seconds) { + minutes = Math.floor(seconds / 60); + seconds = seconds % 60; + + const seconds_padded = String(seconds).padStart(2, "0"); + const minutes_paddded = String(minutes).padStart(2, "0"); + + const formatted_seconds = `Time Remaining: ${minutes_paddded}:${seconds_padded}`; + return formatted_seconds; } function stopAlarm() { pauseAlarm(); + cleanUp(); +} + +function cleanUp() { + clearInterval(intervalID); + clearTimeout(timeoutID); + timeoutID = null; + intervalID = null; } function alarmFinished() { + audio.loop = true; + playAlarm(); console.log("Alarm finished"); - stopAlarm(); } // DO NOT EDIT BELOW HERE From a2d19808fd39fcf25cf771d602740a1b676d3992 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Mon, 3 Aug 2026 13:45:02 +0100 Subject: [PATCH 04/10] Remove setTimout to pass all tests --- Sprint-3/alarmclock/alarmclock.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 4e2a247a0..44f909551 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -6,9 +6,6 @@ let intervalID; let timeoutID; let display; -// document.getElementById("set").addEventListener("click", setAlarm); -// document.getElementById("stop").addEventListener("click", stopAlarm); - function setAlarm() { stopAlarm(); @@ -24,10 +21,6 @@ function setAlarm() { display.textContent = formatTime(timeLeft); - if (!timeoutID) { - timeoutID = setTimeout(alarmFinished, timeLeft * oneSecondInMilliseconds); - } - if (!intervalID) { intervalID = setInterval(updateTimer, 1000); } @@ -41,6 +34,7 @@ function updateTimer() { display.textContent = formatTime(timeLeft); if (timeLeft <= 0) { + alarmFinished(); cleanUp(); } } From 6a98e1c97fd6febd0a0c618dc94a2fa53c1c695b Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 8 Aug 2026 09:03:53 +0100 Subject: [PATCH 05/10] Change case and add check to avoid negative numbers input --- Sprint-3/alarmclock/alarmclock.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 44f909551..e7f1d9073 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,3 @@ -const oneSecondInMilliseconds = 1000; const lengthOfAlarmSound = 20000; let timeLeft; @@ -15,7 +14,8 @@ function setAlarm() { // validate result const result = parseInt(timeLeft); - if (isNaN(result)) { + console.log(result); + if (isNaN(result) || result < 0) { return; } @@ -41,14 +41,14 @@ function updateTimer() { // give a time in seconds function formatTime(seconds) { - minutes = Math.floor(seconds / 60); + const minutes = Math.floor(seconds / 60); seconds = seconds % 60; - const seconds_padded = String(seconds).padStart(2, "0"); - const minutes_paddded = String(minutes).padStart(2, "0"); + const secondsPadded = String(seconds).padStart(2, "0"); + const minutesPaddded = String(minutes).padStart(2, "0"); - const formatted_seconds = `Time Remaining: ${minutes_paddded}:${seconds_padded}`; - return formatted_seconds; + const formattedPeconds = `Time Remaining: ${minutesPaddded}:${secondsPadded}`; + return formattedPeconds; } function stopAlarm() { From d53501a291dea010bfb455beb5a6f4a6be1569ee Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 8 Aug 2026 14:34:58 +0100 Subject: [PATCH 06/10] Check if whole number --- 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 e7f1d9073..5ee45b37c 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -15,7 +15,7 @@ function setAlarm() { // validate result const result = parseInt(timeLeft); console.log(result); - if (isNaN(result) || result < 0) { + if (isNaN(result) || result < 0 || !Number.isInteger(result)) { return; } From 512d598bcbbf391120605a806014b2bd75ee528f Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Tue, 11 Aug 2026 19:30:57 +0100 Subject: [PATCH 07/10] Fix input validation --- Sprint-3/alarmclock/alarmclock.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 5ee45b37c..bad282fc8 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -13,11 +13,11 @@ function setAlarm() { display = document.getElementById("timeRemaining"); // validate result - const result = parseInt(timeLeft); - console.log(result); - if (isNaN(result) || result < 0 || !Number.isInteger(result)) { + const result = Number(timeLeft); + if (!Number.isInteger(result) || result < 0) { return; } + timeLeft = result; display.textContent = formatTime(timeLeft); From 011759650ae4c1ddedbb7c8403ca4db498bec1d6 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Wed, 12 Aug 2026 21:34:43 +0100 Subject: [PATCH 08/10] Remove unused variable timeoutID --- Sprint-3/alarmclock/alarmclock.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index bad282fc8..8ec441611 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -2,7 +2,6 @@ const lengthOfAlarmSound = 20000; let timeLeft; let intervalID; -let timeoutID; let display; function setAlarm() { @@ -58,8 +57,6 @@ function stopAlarm() { function cleanUp() { clearInterval(intervalID); - clearTimeout(timeoutID); - timeoutID = null; intervalID = null; } From 41568f28ea09eef09aba60fce2784c621101e7e3 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Wed, 12 Aug 2026 21:37:29 +0100 Subject: [PATCH 09/10] Don't start alarm if input is 0 --- 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 8ec441611..e65bf9b69 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -13,7 +13,7 @@ function setAlarm() { // validate result const result = Number(timeLeft); - if (!Number.isInteger(result) || result < 0) { + if (!Number.isInteger(result) || result <= 0) { return; } timeLeft = result; From 5a04895876e4220aba74a401f1e61834767225b5 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Wed, 12 Aug 2026 21:40:53 +0100 Subject: [PATCH 10/10] Properly cancel if stop pressed --- 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 e65bf9b69..49c3d45f6 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,7 @@ const lengthOfAlarmSound = 20000; +document.getElementById("stop").addEventListener("click", stopAlarm); + let timeLeft; let intervalID; let display;