From 6b2d3058ab68e1c066244e255e8a9fe81d3f7699 Mon Sep 17 00:00:00 2001 From: saff-coder Date: Thu, 20 Nov 2025 19:20:27 +0000 Subject: [PATCH 1/3] updated the title in the index file --- 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..cea64fbbc 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app>
From 43bd81b98b3496e9ac6f300eae3faec955c7275c Mon Sep 17 00:00:00 2001 From: saff-coder Date: Sat, 22 Nov 2025 14:57:37 +0000 Subject: [PATCH 2/3] i completed my alarm clock functions --- Sprint-3/alarmclock/alarmclock.js | 85 ++++++++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 2 +- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..7af85a40b 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,87 @@ -function setAlarm() {} +// Keep track of the countdown +let countdownId = null; +let remainingSeconds = 0; + +// Turn seconds into "mm:ss" +function formatTime(totalSeconds) { + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + + const minutesString = String(minutes).padStart(2, "0"); + const secondsString = String(seconds).padStart(2, "0"); + + return `${minutesString}:${secondsString}`; +} + +// Update the text at the top: "Time Remaining: mm:ss" +function updateTimeDisplay() { + const titleElement = document.getElementById("timeRemaining"); + if (!titleElement) return; // safety check + + titleElement.textContent = `Time Remaining: ${formatTime(remainingSeconds)}`; +} + +// Called when you click the "Set Alarm" button +function setAlarm() { + const input = document.getElementById("alarmSet"); + if (!input) return; + + const seconds = Number(input.value); +document.body.style.backgroundColor = "red"; + + // Ignore invalid or non-positive numbers + if (Number.isNaN(seconds) || seconds <= 0) { + return; + } + + // If a countdown is already running, stop it first + if (countdownId !== null) { + clearInterval(countdownId); + countdownId = null; + } + + remainingSeconds = seconds; + updateTimeDisplay(); + + // Start a new countdown + countdownId = setInterval(() => { + remainingSeconds -= 1; + updateTimeDisplay(); + + if (remainingSeconds <= 0) { + // Make sure we end at 00:00 + remainingSeconds = 0; + updateTimeDisplay(); + + // Stop the interval + clearInterval(countdownId); + countdownId = null; + + // Play the alarm sound + playAlarm(); + } + }, 1000); +} + +// Called when you click the "Stop Alarm" button +function stopAlarm() { + // Stop the countdown if it is running + if (countdownId !== null) { + clearInterval(countdownId); + countdownId = null; + } + + // Reset the time to 0 and update the display + remainingSeconds = 0; + updateTimeDisplay(); + + // Try to stop the audio (this assumes there is an