From 7f63885aff742bdd61f6b85bb2a6b5420555c83c Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Wed, 18 Mar 2026 12:44:11 +0000 Subject: [PATCH 1/2] Build alarm clock countdown functionality with sound and stop feature --- Sprint-3/alarmclock/alarmclock.js | 38 +++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..40a2aa922 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,7 +1,40 @@ -function setAlarm() {} +function setAlarm() { + const input = document.getElementById("alarmSet").value; + + if (!input || input <= 0) { + alert("Please enter a valid number"); + return; + } + + let timeRemaining = parseInt(input); + const display = document.getElementById("timeRemaining"); + + // Show initial time + display.textContent = `Time Remaining: 00:${timeRemaining + .toString() + .padStart(2, "0")}`; + + // Clear any previous timer + clearInterval(countdown); + + countdown = setInterval(() => { + timeRemaining--; + + display.textContent = `Time Remaining: 00:${timeRemaining + .toString() + .padStart(2, "0")}`; + + if (timeRemaining === 0) { + clearInterval(countdown); + playAlarm(); + } + }, 1000); +} // DO NOT EDIT BELOW HERE +let countdown; // 👈 needed for timer control + var audio = new Audio("alarmsound.mp3"); function setup() { @@ -20,6 +53,7 @@ function playAlarm() { function pauseAlarm() { audio.pause(); + clearInterval(countdown); } -window.onload = setup; +window.onload = setup; \ No newline at end of file From b5c66efba7b034e3b68a7172c149e105e70895f9 Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Sat, 21 Mar 2026 22:42:10 +0000 Subject: [PATCH 2/2] fix: correct time formatting for minutes and seconds --- Sprint-3/alarmclock/alarmclock.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 40a2aa922..7c954d1c2 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -9,10 +9,10 @@ function setAlarm() { let timeRemaining = parseInt(input); const display = document.getElementById("timeRemaining"); - // Show initial time - display.textContent = `Time Remaining: 00:${timeRemaining - .toString() - .padStart(2, "0")}`; + const minutes = Math.floor(timeRemaining / 60); +const seconds = timeRemaining % 60; + +display.textContent = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; // Clear any previous timer clearInterval(countdown);