From 53fa90f23e51a0aecf94e5be7db577997e87a7b6 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Sat, 7 Mar 2026 14:25:25 +0200 Subject: [PATCH 1/2] implement correct median calculation --- Sprint-1/fix/median.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..f7d2fd653 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,21 @@ // 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; + // Filter out non-numeric values and sort the remaining numbers + const numbers = list + .filter((x) => typeof x === "number" && !isNaN(x)) + .sort((a, b) => a - b); + + if (numbers.length === 0) { + return null; + } + + const mid = Math.floor(numbers.length / 2); + if (numbers.length % 2 === 0) { + return (numbers[mid - 1] + numbers[mid]) / 2; + } else { + return numbers[mid]; + } } module.exports = calculateMedian; From 79e6a16ff4611b5cee7e789e93c778356a65fe47 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Tue, 14 Apr 2026 23:46:02 +0200 Subject: [PATCH 2/2] Add Sprint-3 quote generator only --- Sprint-3/quote-generator/index.html | 6 +++--- Sprint-3/quote-generator/quotes.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..7952b4cd7 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -1,13 +1,13 @@ - + - Title here + Quote Generator -

hello there

+

Quote Generator

diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..ca742f8a9 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -1,3 +1,15 @@ +const quoteP = document.querySelector("#quote"); +const authorP = document.querySelector("#author"); +const button = document.querySelector("#new-quote"); + +function displayQuote() { + const randomQuote = pickFromArray(quotes); + quoteP.innerText = randomQuote.quote; + authorP.innerText = randomQuote.author; +} + +button.addEventListener("click", displayQuote); + // DO NOT EDIT BELOW HERE // pickFromArray is a function which will return one item, at @@ -491,3 +503,4 @@ const quotes = [ ]; // call pickFromArray with the quotes array to check you get a random quote +displayQuote();