From 28a696fb75a585c0a0b6845ebd495d3edf2c06a2 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Tue, 7 Jul 2026 07:29:16 +0100 Subject: [PATCH 1/4] reverted to original --- Sprint-1/fix/median.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..a1e52d497 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,31 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return median; + if (!Array.isArray(list)) { + return null; + } + if (list.length === 0) { + return null; + } + const numbersOnly = list.filter((item) => typeof item === "number"); + if (numbersOnly.length === 0) { + return null; + } + const sorted = [...numbersOnly].sort((a, b) => a - b); + const middleIndex = Math.floor(sorted.length / 2); + if (sorted.length % 2 === 0) { + const median = (sorted[middleIndex - 1] + sorted[middleIndex]) / 2; + return median; + } + return sorted[middleIndex]; } +/* +const middleIndex = Math.floor(list.length / 2); +const median = list.splice(middleIndex, 1)[0]; +return median; +*/ module.exports = calculateMedian; +/* + + */ From cff19af51abaccc5438b6f625a4565711f1ac370 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Tue, 7 Jul 2026 07:45:43 +0100 Subject: [PATCH 2/4] reverted to original --- Sprint-1/fix/median.js | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index a1e52d497..b22590bc6 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,31 +6,9 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { - if (!Array.isArray(list)) { - return null; - } - if (list.length === 0) { - return null; - } - const numbersOnly = list.filter((item) => typeof item === "number"); - if (numbersOnly.length === 0) { - return null; - } - const sorted = [...numbersOnly].sort((a, b) => a - b); - const middleIndex = Math.floor(sorted.length / 2); - if (sorted.length % 2 === 0) { - const median = (sorted[middleIndex - 1] + sorted[middleIndex]) / 2; - return median; - } - return sorted[middleIndex]; + const middleIndex = Math.floor(list.length / 2); + const median = list.splice(middleIndex, 1)[0]; + return median; } -/* -const middleIndex = Math.floor(list.length / 2); -const median = list.splice(middleIndex, 1)[0]; -return median; -*/ module.exports = calculateMedian; -/* - - */ From 9e954803cbd52cd99da4ccd4ba7f12fd1cef5915 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Fri, 7 Aug 2026 20:15:59 +0100 Subject: [PATCH 3/4] implemented the alarmclock function and added some flashing effect on it --- Sprint-3/alarmclock/alarmclock.js | 95 ++++++++++++++++++++++++++++++- Sprint-3/alarmclock/index.html | 37 ++++++------ 2 files changed, 114 insertions(+), 18 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..698eca0ec 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,96 @@ -function setAlarm() {} +// This variable will store the interval so we can stop it later +let flashInterval; + +// This function makes the background flash red and white +function startFlashing() { + let isRed = false; // keeps track of which color we should show + + flashInterval = setInterval(function () { + if (isRed) { + document.body.style.backgroundColor = "white"; + } else { + document.body.style.backgroundColor = "red"; + } + + // Switch the color for next time + isRed = !isRed; + }, 500); // run every half second +} + +// This function stops the flashing and resets the background +function stopFlashing() { + clearInterval(flashInterval); // stop the flashing interval + document.body.style.backgroundColor = "white"; // reset background +} + +function setAlarm() { + // get the value of the input + const input = document.getElementById("alarmSet").value; + + // If nothing was typed, exit the function + if (!input) { + return; + } + + let totalSeconds; + + // If the user typed something like "2:21" + if (input.includes(":")) { + // Split into minutes and seconds + const parts = input.split(":"); + const minutes = Number(parts[0]); + const seconds = Number(parts[1]); + + // Convert everything into total seconds + totalSeconds = minutes * 60 + seconds; + } else { + // Otherwise treat the input as normal seconds + totalSeconds = Number(input); + } + + // This is the countdown number that will go down every second + let timeLeft = totalSeconds; + + // If a previous timer was running, stop it + if (window.countdownTimer) { + clearInterval(window.countdownTimer); + } + + // A simple helper to turn seconds into MM:SS format + function formatTime(seconds) { + const mins = Math.floor(seconds / 60); + const secs = seconds % 60; + + // Make sure both numbers always have two digits + const paddedMins = String(mins).padStart(2, "0"); + const paddedSecs = String(secs).padStart(2, "0"); + + return `${paddedMins}:${paddedSecs}`; + } + + // Show the starting time immediately + document.getElementById("timeRemaining").innerText = + `Time Remaining: ${formatTime(timeLeft)}`; + + // Start the countdown — runs every 1000ms (1 second) + window.countdownTimer = setInterval(() => { + timeLeft--; // reduce by 1 second + + // Update the heading each second + document.getElementById("timeRemaining").innerText = + `Time Remaining: ${formatTime(timeLeft)}`; + + // When the timer reaches zero + if (timeLeft <= 0) { + clearInterval(window.countdownTimer); // stop the countdown + clearInterval(flashInterval); // stop the flashing if it was running + document.getElementById("timeRemaining").innerText = + `Time Remaining: 00:00`; + playAlarm(); // play the alarm sound + startFlashing(); // start flashing the background + } + }, 1000); +} // DO NOT EDIT BELOW HERE @@ -11,6 +103,7 @@ function setup() { document.getElementById("stop").addEventListener("click", () => { pauseAlarm(); + stopFlashing(); // stop flashing if running }); } diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..d54f9f4a0 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,20 +1,23 @@ - - - - - Title here - - -
-

Time Remaining: 00:00

- - - - -
- - - + + + + + Alarm Clock + + + +
+

Time Remaining: 00:00

+ + + + + +
+ + + + \ No newline at end of file From 8e5af8574eb1c32c3a23abff830ca729af2db6a7 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Fri, 7 Aug 2026 20:21:21 +0100 Subject: [PATCH 4/4] Remove unnecessary whitespace in index.html --- Sprint-3/alarmclock/index.html | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index d54f9f4a0..1059d53cc 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,13 +1,11 @@ - Alarm Clock -

Time Remaining: 00:00

@@ -19,5 +17,4 @@

Time Remaining: 00:00

- - \ No newline at end of file +