From e328b18cf90ac31bbedfa5fe8951bd483a80f5c4 Mon Sep 17 00:00:00 2001 From: Khor Biel Date: Sat, 15 Nov 2025 10:43:06 +0000 Subject: [PATCH 1/2] Implemented alarmclock --- Sprint-3/alarmclock/alarmclock.js | 48 ++++++++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..6c7e4b75d 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,50 @@ -function setAlarm() {} +function setAlarm() { + const input = document.getElementById("alarmSet"); + const heading = document.getElementById("timeRemaining"); + + // Read total seconds from input + let totalSeconds = parseInt(input.value, 10); + if (Number.isNaN(totalSeconds) || totalSeconds < 0) { + totalSeconds = 0; + } + + // Format seconds into "MM:SS" + function formatTime(seconds) { + const minutes = Math.floor(seconds / 60); + const secs = seconds % 60; + return `Time Remaining: ${String(minutes).padStart(2, "0")}:${String( + secs + ).padStart(2, "0")}`; + } + + // Immediately set the heading to the initial value + heading.innerText = formatTime(totalSeconds); + + // If a previous interval exists, clear it so we only have one running + if (window._alarmInterval) { + clearInterval(window._alarmInterval); + window._alarmInterval = null; + } + + // Start counting down every 1000ms + window._alarmInterval = setInterval(() => { + totalSeconds -= 1; + + if (totalSeconds <= 0) { + // update to 00:00, stop interval and play alarm + heading.innerText = formatTime(0); + clearInterval(window._alarmInterval); + window._alarmInterval = null; + if (typeof playAlarm === "function") { + playAlarm(); + } + } else { + // update heading with remaining time + heading.innerText = formatTime(totalSeconds); + } + }, 1000); +} + // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..ff2d3b453 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
From f8f147c170f00a2edffaa2b09893e62ad85c7aa5 Mon Sep 17 00:00:00 2001 From: Khor Biel Date: Wed, 19 Nov 2025 23:55:37 +0000 Subject: [PATCH 2/2] Fixed set alarm button --- Sprint-3/alarmclock/alarmclock.js | 19 +++++++++++++++---- Sprint-3/reading-list/index.html | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6c7e4b75d..c49c568b1 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -2,10 +2,21 @@ function setAlarm() { const input = document.getElementById("alarmSet"); const heading = document.getElementById("timeRemaining"); - // Read total seconds from input - let totalSeconds = parseInt(input.value, 10); - if (Number.isNaN(totalSeconds) || totalSeconds < 0) { - totalSeconds = 0; + // Read and trim input + const raw = input.value.trim(); + + // If input is empty, do nothing (don't start the alarm) + if (raw === "") { + heading.innerText = `Time Remaining: 00:00`; + return; + } + + // Parse total seconds from input + let totalSeconds = parseInt(raw, 10); + if (Number.isNaN(totalSeconds) || totalSeconds <= 0) { + // invalid or non-positive input -> do nothing + heading.innerText = `Time Remaining: 00:00`; + return; } // Format seconds into "MM:SS" diff --git a/Sprint-3/reading-list/index.html b/Sprint-3/reading-list/index.html index dbdb0f471..9f3ddbca9 100644 --- a/Sprint-3/reading-list/index.html +++ b/Sprint-3/reading-list/index.html @@ -3,8 +3,8 @@ - - Title here + +