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; 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();