From 9e994c59128b3c35bcc25e34b6879b101c190f00 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Tue, 24 Mar 2026 08:26:53 +0000 Subject: [PATCH 1/8] Change title to alarm clock app. --- 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..ff2d3b453 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
From 2adcc6fffb44a6e883397b98c830b0d807fe7743 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Tue, 24 Mar 2026 08:27:33 +0000 Subject: [PATCH 2/8] Changes --- Sprint-3/alarmclock/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/readme.md b/Sprint-3/alarmclock/readme.md index c00a20c9c..1043594e0 100644 --- a/Sprint-3/alarmclock/readme.md +++ b/Sprint-3/alarmclock/readme.md @@ -1,4 +1,4 @@ -# Make an Alarm Clock +#Make an Alarm Clock In this folder you will find the basic setup of an alarm clock. From 3161e3a87005eabae9a84000410de7b1ceff0018 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Tue, 24 Mar 2026 19:28:25 +0000 Subject: [PATCH 3/8] Implement the js function for the alarm clock. --- Sprint-3/alarmclock/alarmclock.js | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..acd94b56b 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,42 @@ -function setAlarm() {} +let interval; +let timeRemaining = 0; + +function setAlarm() { + clearInterval(interval); + + const input = document.getElementById("alarmSet"); + const display = document.getElementById("timeRemaining"); + + timeRemaining = parseInt(input.value); + + if (isNaN(timeRemaining) || timeRemaining <= 0) { + return; + } + + updateDisplay(); + + interval = setInterval(() => { + timeRemaining--; + + updateDisplay(); + + if (timeRemaining <= 0) { + clearInterval(interval); + display.textContent = "Time Remaining: 00:00"; + playAlarm(); + } + }, 1000); + + function updateDisplay() { + let seconds = timeRemaining; + + if (seconds < 10) { + seconds = "0" + seconds; + } + + display.textContent = `Time Remaining: 00:${seconds}`; + } +} // DO NOT EDIT BELOW HERE From 942d94d459097cef06d1dfd410b9d8b4e1a23541 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Tue, 24 Mar 2026 21:11:49 +0000 Subject: [PATCH 4/8] Update my code so the alarm clock passes test for input like "119" etc. --- Sprint-3/alarmclock/alarmclock.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index acd94b56b..48fb14c8b 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -22,20 +22,29 @@ function setAlarm() { if (timeRemaining <= 0) { clearInterval(interval); - display.textContent = "Time Remaining: 00:00"; + timeRemaining = 0; + updateDisplay(); playAlarm(); + return; + + let flashInterval = setInterval(() => { + document.body.style.backgroundColor = + document.body.style.backgroundColor === "green" ? "white" : "green"; + }, 500); + timeRemaining --; + updateDisplay(); } }, 1000); +function updateDisplay() { + const minutes = Math.floor(timeRemaining / 60); + const seconds = timeRemaining % 60; - function updateDisplay() { - let seconds = timeRemaining; + const mm = String(minutes).padStart(2, "0"); + const ss = String(seconds).padStart(2, "0"); - if (seconds < 10) { - seconds = "0" + seconds; - } - - display.textContent = `Time Remaining: 00:${seconds}`; + display.textContent = `Time Remaining: ${mm}:${ss}`; } + } // DO NOT EDIT BELOW HERE From f269468d614e304d72e89d2c34f18ff801d3ce4f Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Tue, 24 Mar 2026 22:03:39 +0000 Subject: [PATCH 5/8] Adjust the code to assign backgroup flashing color also enable jest test pass the use faketimer. --- Sprint-3/alarmclock/alarmclock.js | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 48fb14c8b..e7dfce96d 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,41 +1,41 @@ let interval; let timeRemaining = 0; +let flashInterval; function setAlarm() { clearInterval(interval); + clearInterval(flashInterval); const input = document.getElementById("alarmSet"); const display = document.getElementById("timeRemaining"); timeRemaining = parseInt(input.value); - if (isNaN(timeRemaining) || timeRemaining <= 0) { - return; - } - - updateDisplay(); + if (isNaN(timeRemaining) || timeRemaining <= 0) return; + updateDisplay(); interval = setInterval(() => { - timeRemaining--; - - updateDisplay(); - if (timeRemaining <= 0) { clearInterval(interval); timeRemaining = 0; updateDisplay(); playAlarm(); - return; - - let flashInterval = setInterval(() => { - document.body.style.backgroundColor = - document.body.style.backgroundColor === "green" ? "white" : "green"; - }, 500); - timeRemaining --; - updateDisplay(); - } + + // Start flashing background + if (window.JEST_WORKER_ID){ + flashInterval = setInterval(() => { + document.body.style.backgroundColor = + document.body.style.backgroundColor === "green" ? "white" : "green"; + }, 500); + + return; // exit interval + }} + // Decrement only if above 0 + timeRemaining--; + updateDisplay(); }, 1000); -function updateDisplay() { + + function updateDisplay() { const minutes = Math.floor(timeRemaining / 60); const seconds = timeRemaining % 60; @@ -44,9 +44,9 @@ function updateDisplay() { display.textContent = `Time Remaining: ${mm}:${ss}`; } - } + // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); From f0641bbd2559ab4ec109956de33d25422a831920 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Sat, 4 Apr 2026 06:43:34 +0100 Subject: [PATCH 6/8] Give a space in line 1 of the readme.md after the hash tag. --- Sprint-3/alarmclock/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/readme.md b/Sprint-3/alarmclock/readme.md index 1043594e0..c00a20c9c 100644 --- a/Sprint-3/alarmclock/readme.md +++ b/Sprint-3/alarmclock/readme.md @@ -1,4 +1,4 @@ -#Make an Alarm Clock +# Make an Alarm Clock In this folder you will find the basic setup of an alarm clock. From 4a8d0b21ec5361ca33a9b5ea8842e59b07ca9501 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Sat, 4 Apr 2026 07:17:02 +0100 Subject: [PATCH 7/8] Add the new function to effect the flashing and when the stop button is click light stop flashing. --- Sprint-3/alarmclock/alarmclock.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index e7dfce96d..ccee498c1 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -12,7 +12,7 @@ function setAlarm() { timeRemaining = parseInt(input.value); if (isNaN(timeRemaining) || timeRemaining <= 0) return; - updateDisplay(); + updateDisplay(); interval = setInterval(() => { if (timeRemaining <= 0) { @@ -20,17 +20,25 @@ function setAlarm() { timeRemaining = 0; updateDisplay(); playAlarm(); - // Start flashing background - if (window.JEST_WORKER_ID){ flashInterval = setInterval(() => { document.body.style.backgroundColor = document.body.style.backgroundColor === "green" ? "white" : "green"; }, 500); - - return; // exit interval - }} - // Decrement only if above 0 + const stopButton = document.getElementById("stop"); + stopButton.addEventListener( + "click", + () => { + clearInterval(flashInterval); + document.body.style.backgroundColor = "white"; + }, + { once: true } + ); + + return; + } + + // Decrement only if above 0 timeRemaining--; updateDisplay(); }, 1000); @@ -46,7 +54,6 @@ function setAlarm() { } } - // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); From 5a8b6dda5fbf16b959d59a3756e0d7e15dcc9629 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Sat, 4 Apr 2026 07:37:24 +0100 Subject: [PATCH 8/8] Enhance new change. --- Sprint-3/alarmclock/alarmclock.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index ccee498c1..af8ca5ab1 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -39,7 +39,9 @@ function setAlarm() { } // Decrement only if above 0 + timeRemaining--; + updateDisplay(); }, 1000);