From c26fd30017f2e4c4bc4726ab8928b8a6be11fd39 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Fri, 17 Jul 2026 22:19:10 +0100 Subject: [PATCH 1/3] alarm clock final commit --- Sprint-3/alarmclock/alarmclock.js | 39 +++++++++++++++++++++++++- Sprint-3/alarmclock/alarmclock.test.js | 1 + Sprint-3/alarmclock/index.html | 6 ++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..cdf7e0e85 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,39 @@ -function setAlarm() {} +function setAlarm() { + //change the time remaining and set the remaining time + //into the second. + + let alarmInterval; + const InputField = document.querySelector("#alarmSet"); + let timeRemaining = InputField.value; + + function updateDisplay() { + const timedisplay = document.querySelector("#timeRemaining"); + const Minute = Math.floor(timeRemaining / 60); + const Second = timeRemaining % 60; + + const formatMinute = String(Minute).padStart(2, "0"); + const formatSecond = String(Second).padStart(2, "0"); + + timedisplay.innerText = `Time Remaining: ${formatMinute}:${formatSecond}`; + } + + updateDisplay(); + //set a variable to count three actions: + // count -1; + // Show what is the remaining time; + // if it goes to zero, beep the sound and stop the counting + + alarmInterval = setInterval(() => { + timeRemaining = timeRemaining - 1; + + updateDisplay(); + + if (timeRemaining === 0) { + playAlarm(); + clearInterval(alarmInterval); + } + }, 1000); +} // DO NOT EDIT BELOW HERE @@ -20,6 +55,8 @@ function playAlarm() { function pauseAlarm() { audio.pause(); + + clearInterval(alarmInterval); } window.onload = setup; diff --git a/Sprint-3/alarmclock/alarmclock.test.js b/Sprint-3/alarmclock/alarmclock.test.js index 85b7356dc..6fdfa258f 100644 --- a/Sprint-3/alarmclock/alarmclock.test.js +++ b/Sprint-3/alarmclock/alarmclock.test.js @@ -44,6 +44,7 @@ test("should set heading when button is clicked", () => { button.click(); expect(heading).toHaveTextContent("Time Remaining: 00:19"); + }); test("should split values over 60 seconds into minutes and seconds", () => { diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..26a601edb 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -18,3 +18,9 @@

Time Remaining: 00:00

+ + + + + + From 7bc2350fbef5f8986750f5849171b4927f3962fd Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Fri, 31 Jul 2026 12:13:33 +0100 Subject: [PATCH 2/3] FIix bug and update alarmclock sound --- Sprint-3/alarmclock/alarmclock.js | 21 +++++++++++++-------- Sprint-3/alarmclock/index.html | 10 ++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index cdf7e0e85..0b9404ee7 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,20 +1,27 @@ +let alarmInterval; + function setAlarm() { //change the time remaining and set the remaining time //into the second. + clearInterval(alarmInterval); - let alarmInterval; - const InputField = document.querySelector("#alarmSet"); - let timeRemaining = InputField.value; + const InputField = document.getElementById("alarmSet"); + let timeRemaining = Number(InputField.value); + + if (!InputField.value || InputField.value < 0) { + alert("Please enter a valid time in seconds"); + return; + } function updateDisplay() { - const timedisplay = document.querySelector("#timeRemaining"); + const timeDisplay = document.getElementById("timeRemaining"); const Minute = Math.floor(timeRemaining / 60); const Second = timeRemaining % 60; const formatMinute = String(Minute).padStart(2, "0"); const formatSecond = String(Second).padStart(2, "0"); - timedisplay.innerText = `Time Remaining: ${formatMinute}:${formatSecond}`; + timeDisplay.innerText = `Time Remaining: ${formatMinute}:${formatSecond}`; } updateDisplay(); @@ -22,7 +29,6 @@ function setAlarm() { // count -1; // Show what is the remaining time; // if it goes to zero, beep the sound and stop the counting - alarmInterval = setInterval(() => { timeRemaining = timeRemaining - 1; @@ -54,9 +60,8 @@ function playAlarm() { } function pauseAlarm() { - audio.pause(); - clearInterval(alarmInterval); + audio.pause(); } window.onload = setup; diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 26a601edb..048439063 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock
@@ -17,10 +17,4 @@

Time Remaining: 00:00

- - - - - - - + \ No newline at end of file From c179e8ce9d425368ece6d7beff4248ba38fe74da Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Fri, 31 Jul 2026 15:10:26 +0100 Subject: [PATCH 3/3] Stop alarm button --- 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 0b9404ee7..09fe252a3 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -64,4 +64,4 @@ function pauseAlarm() { audio.pause(); } -window.onload = setup; +window.onload = setup; \ No newline at end of file