From be69028207bbb3f61990d62ad6232b4420d7cf51 Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 3 Aug 2026 17:23:20 +0100 Subject: [PATCH 1/6] Change title to 'Alarm Clock App' in index.html --- 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..5a3801414 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock App
From a8213dbd397445a91e2af002d26e47e092314d6c Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 3 Aug 2026 17:28:20 +0100 Subject: [PATCH 2/6] Implement alarm clock functionality with countdown --- Sprint-3/alarmclock/alarmclock.js | 133 ++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..e894db38d 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,3 +1,4 @@ +/* function setAlarm() {} // DO NOT EDIT BELOW HERE @@ -23,3 +24,135 @@ function pauseAlarm() { } window.onload = setup; +*/ + + +let countdownInterval = null; +let flashInterval = null; +let timeRemaining = 0; +let isPaused = false; + +function formatTime(totalSeconds) { + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + + const padMinutes = String(minutes).padStart(2, "0"); + const padSeconds = String(seconds).padStart(2, "0"); + + return `${padMinutes}:${padSeconds}`; +} + +function updateDisplay() { + const timeRemainingElement = document.getElementById("timeRemaining"); + if (timeRemainingElement) { + timeRemainingElement.innerText = `Time Remaining: ${formatTime(timeRemaining)}`; + } +} + +function startFlashingBackground() { + let isRed = false; + flashInterval = setInterval(() => { + document.body.style.backgroundColor = isRed ? "#ffffff" : "#ff4d4d"; + isRed = !isRed; + }, 500); +} + +function stopFlashingBackground() { + if (flashInterval) { + clearInterval(flashInterval); + flashInterval = null; + } + document.body.style.backgroundColor = ""; +} + +function setAlarm() { + const alarmInput = document.getElementById("alarmSet"); + + // If currently paused, resume countdown + if (isPaused) { + isPaused = false; + startCountdown(); + return; + } + + // If an active alarm is already running, toggle pause state + if (countdownInterval !== null) { + isPaused = true; + clearInterval(countdownInterval); + countdownInterval = null; + return; + } + + // Read time from input field + const inputSeconds = parseInt(alarmInput.value, 10); + if (isNaN(inputSeconds) || inputSeconds <= 0) { + alert("Please enter a valid number of seconds."); + return; + } + + timeRemaining = inputSeconds; + stopFlashingBackground(); + updateDisplay(); + startCountdown(); +} + +function startCountdown() { + // Clear any existing timer before starting a new one + if (countdownInterval) { + clearInterval(countdownInterval); + } + + countdownInterval = setInterval(() => { + timeRemaining -= 1; + updateDisplay(); + + if (timeRemaining <= 0) { + clearInterval(countdownInterval); + countdownInterval = null; + playAlarm(); + startFlashingBackground(); + } + }, 1000); +} + +// Override pauseAlarm to also clear screen effects and reset timers +const originalPauseAlarm = pauseAlarm; +pauseAlarm = function () { + if (typeof originalPauseAlarm === "function") { + originalPauseAlarm(); + } else { + audio.pause(); + } + + // Reset state + if (countdownInterval) { + clearInterval(countdownInterval); + countdownInterval = null; + } + isPaused = false; + stopFlashingBackground(); +}; + +// DO NOT EDIT BELOW HERE + +var audio = new Audio("alarmsound.mp3"); + +function setup() { + document.getElementById("set").addEventListener("click", () => { + setAlarm(); + }); + + document.getElementById("stop").addEventListener("click", () => { + pauseAlarm(); + }); +} + +function playAlarm() { + audio.play(); +} + +function pauseAlarm() { + audio.pause(); +} + +window.onload = setup; From c82784cf0a883ea9898d2d5b8f1cae5fa8e14c30 Mon Sep 17 00:00:00 2001 From: cywong Date: Sun, 9 Aug 2026 16:20:50 +0100 Subject: [PATCH 3/6] Add timeRemainingElement initialization in setup function Initialize timeRemainingElement and assign it to the DOM element. --- Sprint-3/alarmclock/alarmclock.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index e894db38d..545ec5648 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -138,6 +138,10 @@ pauseAlarm = function () { var audio = new Audio("alarmsound.mp3"); function setup() { + let timeRemainingElement; + + timeRemainingElement = document.getElementById("timeRemaining"); + document.getElementById("set").addEventListener("click", () => { setAlarm(); }); From c32b7186162bf490888cb55179dfb63783cbf620 Mon Sep 17 00:00:00 2001 From: cywong Date: Sun, 9 Aug 2026 16:21:46 +0100 Subject: [PATCH 4/6] Refactor timeRemainingElement declaration Declare timeRemainingElement variable at the top for better scope management. --- Sprint-3/alarmclock/alarmclock.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 545ec5648..5a7922b70 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -29,6 +29,8 @@ window.onload = setup; let countdownInterval = null; let flashInterval = null; +let timeRemainingElement = null; + let timeRemaining = 0; let isPaused = false; @@ -138,7 +140,6 @@ pauseAlarm = function () { var audio = new Audio("alarmsound.mp3"); function setup() { - let timeRemainingElement; timeRemainingElement = document.getElementById("timeRemaining"); From 4d7dd24a6c43afd17871e28686094940464342b8 Mon Sep 17 00:00:00 2001 From: cywong Date: Sun, 9 Aug 2026 16:30:17 +0100 Subject: [PATCH 5/6] Modify updateDisplay to accept timeRemaining parameter --- Sprint-3/alarmclock/alarmclock.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 5a7922b70..9a9f8d6b9 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -44,10 +44,9 @@ function formatTime(totalSeconds) { return `${padMinutes}:${padSeconds}`; } -function updateDisplay() { - const timeRemainingElement = document.getElementById("timeRemaining"); +function updateDisplay(ptimeRemaining) { if (timeRemainingElement) { - timeRemainingElement.innerText = `Time Remaining: ${formatTime(timeRemaining)}`; + timeRemainingElement.innerText = `Time Remaining: ${formatTime(ptimeRemaining)}`; } } @@ -94,7 +93,7 @@ function setAlarm() { timeRemaining = inputSeconds; stopFlashingBackground(); - updateDisplay(); + updateDisplay(timeRemaining); startCountdown(); } @@ -106,7 +105,7 @@ function startCountdown() { countdownInterval = setInterval(() => { timeRemaining -= 1; - updateDisplay(); + updateDisplay(timeRemaining); if (timeRemaining <= 0) { clearInterval(countdownInterval); From 1d5e510afb59af8c26b8bebacf413b38e1b46361 Mon Sep 17 00:00:00 2001 From: cywong Date: Sun, 9 Aug 2026 16:31:21 +0100 Subject: [PATCH 6/6] Clean up alarmclock.js by removing unused code Removed commented-out alarm functions and setup code. --- Sprint-3/alarmclock/alarmclock.js | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 9a9f8d6b9..01f409b70 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,32 +1,3 @@ -/* -function setAlarm() {} - -// DO NOT EDIT BELOW HERE - -var audio = new Audio("alarmsound.mp3"); - -function setup() { - document.getElementById("set").addEventListener("click", () => { - setAlarm(); - }); - - document.getElementById("stop").addEventListener("click", () => { - pauseAlarm(); - }); -} - -function playAlarm() { - audio.play(); -} - -function pauseAlarm() { - audio.pause(); -} - -window.onload = setup; -*/ - - let countdownInterval = null; let flashInterval = null; let timeRemainingElement = null;