-
Time Remaining: 00:00
+
Time Remaining: 00:00
From 27b8dc63822765e92dbb0b7e81c8d6fb3b32c9c3 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Thu, 13 Aug 2026 19:52:56 +0100
Subject: [PATCH 3/4] made all suggested changes
---
Sprint-3/alarmclock/alarmclock.js | 47 ++++++++++++++++++++++---------
Sprint-3/alarmclock/index.html | 3 +-
2 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js
index b09784d70..e82bdda01 100644
--- a/Sprint-3/alarmclock/alarmclock.js
+++ b/Sprint-3/alarmclock/alarmclock.js
@@ -1,29 +1,50 @@
const input = document.getElementById("alarmSet");
-const timeDisplay = document.getElementById("timeDisplay");
+const timeRemaining = document.getElementById("timeRemaining");
+const message = document.getElementById("message");
-function setAlarm() {
- let timeInput = Number(input.value);
- let minutes = Math.floor(timeInput / 60);
- let seconds = timeInput % 60;
+let intervalId = null;
+
+function getTime() {
+ const time = Number(input.value);
+ if (!(Number.isFinite(time) && Number.isInteger(time) && time >= 1)) {
+ message.textContent = "Enter a valid number";
+ return null;
+ }
+ return time;
+}
+function updateTime(updatedTime) {
+ const time = updatedTime;
+ let minutes = Math.floor(time / 60);
+ let seconds = time % 60;
minutes = minutes.toString().padStart(2, "0");
seconds = seconds.toString().padStart(2, "0");
- timeDisplay.textContent = `${minutes}:${seconds}`;
+ timeRemaining.textContent = `Time Remaining: ${minutes}:${seconds}`;
+}
- const alarm = setInterval(() => {
+function setAlarm() {
+ let timeInput = getTime();
+ if (timeInput === null) {
+ return;
+ }
+ resetAlarm();
+ updateTime(timeInput);
+ intervalId = setInterval(() => {
timeInput--;
- let remainingMinutes = Math.floor(timeInput / 60);
- let remainingSeconds = timeInput % 60;
- remainingMinutes = remainingMinutes.toString().padStart(2, "0");
- remainingSeconds = remainingSeconds.toString().padStart(2, "0");
- timeDisplay.textContent = `${remainingMinutes}:${remainingSeconds}`;
+ updateTime(timeInput);
if (timeInput === 0) {
playAlarm();
- clearInterval(alarm);
+ clearInterval(intervalId);
+ intervalId = null;
}
}, 1000);
}
+function resetAlarm() {
+ clearInterval(intervalId);
+ intervalId = null;
+ timeRemaining.textContent = `Time Remaining: 00:00`;
+}
// DO NOT EDIT BELOW HERE
var audio = new Audio("alarmsound.mp3");
diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html
index b74c4db71..229427d35 100644
--- a/Sprint-3/alarmclock/index.html
+++ b/Sprint-3/alarmclock/index.html
@@ -9,7 +9,8 @@
-
Time Remaining: 00:00
+ Time Remaining: 00:00
+
From 25681715e0be54f71e4a52227ee1f7d1b3cd9a04 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Thu, 13 Aug 2026 21:06:59 +0100
Subject: [PATCH 4/4] made all suggested changes
---
Sprint-3/alarmclock/alarmclock.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js
index e82bdda01..6765b722e 100644
--- a/Sprint-3/alarmclock/alarmclock.js
+++ b/Sprint-3/alarmclock/alarmclock.js
@@ -6,15 +6,14 @@ let intervalId = null;
function getTime() {
const time = Number(input.value);
- if (!(Number.isFinite(time) && Number.isInteger(time) && time >= 1)) {
+ if (!(Number.isInteger(time) && time >= 1)) {
message.textContent = "Enter a valid number";
return null;
}
return time;
}
-function updateTime(updatedTime) {
- const time = updatedTime;
+function updateTime(time) {
let minutes = Math.floor(time / 60);
let seconds = time % 60;
minutes = minutes.toString().padStart(2, "0");
@@ -43,7 +42,7 @@ function setAlarm() {
function resetAlarm() {
clearInterval(intervalId);
intervalId = null;
- timeRemaining.textContent = `Time Remaining: 00:00`;
+ updateTime(0);
}
// DO NOT EDIT BELOW HERE