From d0554adab85d91fb8bcf8781ef659c397af48c29 Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Sun, 19 Jul 2026 12:56:39 +0100 Subject: [PATCH 1/4] Update the title to 'Alarm clock app' --- Sprint-3/alarmclock/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..66748001e 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,10 +1,10 @@ - + - Title here + Alarm clock app
From 83993fd918544190394e2d712036baebe3d958c7 Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Sun, 19 Jul 2026 16:40:39 +0100 Subject: [PATCH 2/4] Implement alarm clock countdown logic --- Sprint-3/alarmclock/alarmclock.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..9a78d7b5f 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,23 @@ -function setAlarm() {} +function setAlarm() { + const timeInput = document.getElementById("alarmSet"); + let remainingTime = Number(timeInput.value); + const timeRemainingDisplay = document.getElementById("timeRemaining"); + + timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`; + const countdownInterval = setInterval(() => { + remainingTime -= 1; + if (remainingTime === 0) { + playAlarm(); + clearInterval(countdownInterval); + } + timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`; + }, 1000); +} +function formatTime(seconds) { + const mm = String(Math.floor(seconds / 60)).padStart(2, "0"); + const ss = String(seconds % 60).padStart(2, "0"); + return `${mm}:${ss}`; +} // DO NOT EDIT BELOW HERE From 427106d7c024977a34e42f197344893c09f03f14 Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Mon, 27 Jul 2026 20:09:36 +0100 Subject: [PATCH 3/4] Add input validation to prevent empty or invalid alarm values --- Sprint-3/alarmclock/alarmclock.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 9a78d7b5f..2e6fa1d16 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,6 +1,12 @@ function setAlarm() { const timeInput = document.getElementById("alarmSet"); let remainingTime = Number(timeInput.value); + + if (!timeInput.value || remainingTime <= 0) { + alert("Please set a valid time!"); + return; + } + const timeRemainingDisplay = document.getElementById("timeRemaining"); timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`; From fee8dfb819397df351f1e9acd297792708eec80e Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Mon, 27 Jul 2026 20:27:00 +0100 Subject: [PATCH 4/4] Fix countdown issue by stopping the previous timer before starting a new one --- Sprint-3/alarmclock/alarmclock.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 2e6fa1d16..f61a114bf 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,3 +1,5 @@ +let countdownInterval = null; + function setAlarm() { const timeInput = document.getElementById("alarmSet"); let remainingTime = Number(timeInput.value); @@ -9,8 +11,12 @@ function setAlarm() { const timeRemainingDisplay = document.getElementById("timeRemaining"); + if (countdownInterval !== null) { + clearInterval(countdownInterval); + } + timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`; - const countdownInterval = setInterval(() => { + countdownInterval = setInterval(() => { remainingTime -= 1; if (remainingTime === 0) { playAlarm();