From 7f63885aff742bdd61f6b85bb2a6b5420555c83c Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Wed, 18 Mar 2026 12:44:11 +0000 Subject: [PATCH 1/3] 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/3] 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); From b9165a5e5e155e16bbfdb141fe858612f73791ed Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Wed, 15 Apr 2026 17:52:30 +0100 Subject: [PATCH 3/3] Fix: alarmclock validation, formatting, and missing function --- Sprint-3/alarmclock/alarmclock.js | 70 +++++++++++++------------------ 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 7c954d1c2..ab8d99474 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,59 +1,47 @@ -function setAlarm() { - const input = document.getElementById("alarmSet").value; +let countdown; - if (!input || input <= 0) { - alert("Please enter a valid number"); - return; - } - - let timeRemaining = parseInt(input); +function startTimer(input) { const display = document.getElementById("timeRemaining"); - const minutes = Math.floor(timeRemaining / 60); -const seconds = timeRemaining % 60; + // Validate input + const timeRemaining = Number(input); + + if (isNaN(timeRemaining) || timeRemaining <= 0) { + display.textContent = "Please enter a valid number"; + return; + } -display.textContent = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; + let remaining = timeRemaining; // Clear any previous timer clearInterval(countdown); + function updateDisplay() { + const minutes = Math.floor(remaining / 60); + const seconds = remaining % 60; + + display.textContent = `Time Remaining: ${String(minutes).padStart( + 2, + "0" + )}:${String(seconds).padStart(2, "0")}`; + } + + // Show initial time + updateDisplay(); + countdown = setInterval(() => { - timeRemaining--; + remaining--; - display.textContent = `Time Remaining: 00:${timeRemaining - .toString() - .padStart(2, "0")}`; + updateDisplay(); - if (timeRemaining === 0) { + if (remaining <= 0) { clearInterval(countdown); playAlarm(); } }, 1000); } -// DO NOT EDIT BELOW HERE - -let countdown; // 👈 needed for timer control - -var audio = new Audio("alarmsound.mp3"); - -function setup() { - document.getElementById("set").addEventListener("click", () => { - setAlarm(); - }); - - document.getElementById("stop").addEventListener("click", () => { - pauseAlarm(); - }); -} - +// :white_check_mark: Fix missing function function playAlarm() { - audio.play(); -} - -function pauseAlarm() { - audio.pause(); - clearInterval(countdown); -} - -window.onload = setup; \ No newline at end of file + alert("Time's up!"); +} \ No newline at end of file