From 28a696fb75a585c0a0b6845ebd495d3edf2c06a2 Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Tue, 7 Jul 2026 07:29:16 +0100 Subject: [PATCH 1/5] 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/5] 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/5] 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/5] 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 + From eb2df3485b3bdfa698192b1811b65af087cdb53b Mon Sep 17 00:00:00 2001 From: Yonatan Teklemariam Date: Thu, 13 Aug 2026 07:28:53 +0100 Subject: [PATCH 5/5] cleaned and restructured the script.js file, replace the flashing effect with css animation, fixed missing functions and broken format logic --- Sprint-3/alarmclock/alarmclock.js | 138 ++++++++++++++++-------------- Sprint-3/alarmclock/index.html | 6 +- Sprint-3/alarmclock/style.css | 24 ++++++ 3 files changed, 102 insertions(+), 66 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 698eca0ec..8fe5cf4e9 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,97 +1,107 @@ -// This variable will store the interval so we can stop it later -let flashInterval; +// This is the countdown number that will go down every second +let countdownTimer; -// 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 + document.body.classList.add("flash-background"); } -// This function stops the flashing and resets the background function stopFlashing() { - clearInterval(flashInterval); // stop the flashing interval - document.body.style.backgroundColor = "white"; // reset background + document.body.classList.remove("flash-background"); } function setAlarm() { - // get the value of the input - const input = document.getElementById("alarmSet").value; + const rawInput = document.getElementById("alarmSet").value.trim(); - // If nothing was typed, exit the function - if (!input) { + // Reject empty input + if (rawInput === "") { + alert("Please enter a time."); return; } - let totalSeconds; + // 2. Parse input → returns either a number of seconds or null + const totalSeconds = parseInput(rawInput); - // 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]); + // 3. Reject invalid parsed values + if (totalSeconds === null || totalSeconds <= 0) { + alert("Please enter a valid positive time."); + return; + } - // Convert everything into total seconds - totalSeconds = minutes * 60 + seconds; - } else { - // Otherwise treat the input as normal seconds - totalSeconds = Number(input); + // 4. Reject extremely large values + if (totalSeconds > 36000) { + alert("Please enter a time less than 10 hours."); + return; } - // This is the countdown number that will go down every second - let timeLeft = totalSeconds; + stopFlashing(); + pauseAlarm(); + + // 5. If we reach here → input is valid + startCountdown(totalSeconds); +} + +function parseInput(rawInput) { + if (rawInput.includes(":")) { + const [minsStr, secsStr] = rawInput.split(":"); + + const mins = Number(minsStr); + const secs = Number(secsStr); + + if ( + Number.isNaN(mins) || + Number.isNaN(secs) || + mins < 0 || + secs < 0 || + secs >= 60 + ) { + return null; + } - // If a previous timer was running, stop it - if (window.countdownTimer) { - clearInterval(window.countdownTimer); + return mins * 60 + secs; } - // A simple helper to turn seconds into MM:SS format - function formatTime(seconds) { - const mins = Math.floor(seconds / 60); - const secs = seconds % 60; + const secs = Number(rawInput); + return Number.isNaN(secs) ? null : secs; +} - // Make sure both numbers always have two digits - const paddedMins = String(mins).padStart(2, "0"); - const paddedSecs = String(secs).padStart(2, "0"); +function startCountdown(totalSeconds) { + let timeLeft = totalSeconds; - return `${paddedMins}:${paddedSecs}`; + if (countdownTimer) { + clearInterval(countdownTimer); } - // 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 + updateDisplay(timeLeft); - // Update the heading each second - document.getElementById("timeRemaining").innerText = - `Time Remaining: ${formatTime(timeLeft)}`; + countdownTimer = setInterval(() => { + timeLeft--; + updateDisplay(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 + clearInterval(countdownTimer); + playAlarm(); + startFlashing(); } }, 1000); } +// 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}`; +} + +function updateDisplay(seconds) { + document.getElementById("timeRemaining").innerText = + `Time Remaining: ${formatTime(seconds)}`; +} + // 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 1059d53cc..23b5f31ef 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,11 +1,12 @@ + Alarm Clock - +

Time Remaining: 00:00

@@ -17,4 +18,5 @@

Time Remaining: 00:00

- + + \ No newline at end of file diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b..47a06f9bb 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -13,3 +13,27 @@ h1 { text-align: center; } + +/* flashing effect for the alarm app */ +@keyframes colorRipple { + 0% { + background-color: #ffffff; + } /* White */ + 25% { + background-color: #ff6b6b; + } /* Light Coral / Soft Red */ + 50% { + background-color: #feca57; + } /* Mango / Warm Yellow-Orange */ + 75% { + background-color: #48dbfb; + } /* Sky Blue / Light Aqua */ + 100% { + background-color: #ffffff; + } /* White */ +} + +/* apply the flashing effect to the body when the alarm is triggered */ +.flash-background { + animation: colorRipple 0.8s infinite; +}