From 35a3254661dc41a1353f7bb77a576dc9d7a8bcfc Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 6 Dec 2025 21:44:15 +0100 Subject: [PATCH 1/2] implement functions --- Sprint-3/alarmclock/Alarm clock app.html | 20 +++++++++++ Sprint-3/alarmclock/alarmclock.js | 43 +++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Sprint-3/alarmclock/Alarm clock app.html diff --git a/Sprint-3/alarmclock/Alarm clock app.html b/Sprint-3/alarmclock/Alarm clock app.html new file mode 100644 index 000000000..4a91379d3 --- /dev/null +++ b/Sprint-3/alarmclock/Alarm clock app.html @@ -0,0 +1,20 @@ + + + + + + + Alarm Clock App + + +
+

Time Remaining: 00:00

+ + + + + +
+ + + diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..c439c6a8a 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,45 @@ -function setAlarm() {} +let timeRemaining = 0; +let timer = null; + +function setAlarm() { + timeRemaining = document.getElementById("alarmSet").value; + + if (timeRemaining <= 0) { + alert("Enter a valid time in seconds!"); + return; + } + + updateTimeDisplay(); + + timer = setInterval(function () { + timeRemaining--; + updateTimeDisplay(); + + if (timeRemaining <= 0) { + clearInterval(timer); + document.body.style.backgroundColor = "red"; + playAlarm(); + } + }, 1000); +} + +function updateTimeDisplay() { + const minutes = Math.floor(timeRemaining / 60); + const seconds = timeRemaining % 60; + document.getElementById( + "timeRemaining" + ).innerText = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String( + seconds + ).padStart(2, "0")}`; +} + +function stopAlarmAndReset() { + clearInterval(timer); + timeRemaining = 0; + updateTimeDisplay(); + document.body.style.backgroundColor = ""; + pauseAlarm(); +} // DO NOT EDIT BELOW HERE From e6f4201efd439f2da499d579fb98a90c7162f1fc Mon Sep 17 00:00:00 2001 From: Pinx-pinx Date: Sat, 6 Dec 2025 23:05:03 +0100 Subject: [PATCH 2/2] modify --- 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