From d7eaca1460aec8c6bfec2a39fba52acd0fb3fd5e Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Thu, 16 Jul 2026 15:05:32 +0100 Subject: [PATCH 1/3] quotes.js --- Sprint-3/quote-generator/quotes.js | 31 ++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..2bfba74b4 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -1,24 +1,42 @@ // DO NOT EDIT BELOW HERE - +// // pickFromArray is a function which will return one item, at // random, from the given array. -// + // Parameters // ---------- // choices: an array of items to pick from. // + // Returns // ------- // One item at random from the given array. // + // Examples of use // --------------- // pickFromArray(['a','b','c','d']) // maybe returns 'c' // You don't need to change this function -function pickFromArray(choices) { - return choices[Math.floor(Math.random() * choices.length)]; + +function pickFromArray(quotes) { + return quotes[Math.floor(Math.random() * quotes.length)]; } +// First condition: When a person click the button, it should generate back a quote; + +function updateWebpageWithQuote() { + const elem = document.querySelector("#quote"); + const elem2 = document.querySelector("#author"); + + // store into the variable + const elem3 = pickFromArray(quotes); + elem.innerText = elem3.quote; + elem2.innerText = elem3.author; +} + +// Second condition: when a person enter the website, it should have a quote appear; + +// Third condition: when a person clicks the button each time, it should have different quote. . // A list of quotes you can use in your app. // DO NOT modify this array, otherwise the tests may break! @@ -490,4 +508,9 @@ const quotes = [ }, ]; +const buttonElem = document.querySelector("#new-quote"); + +buttonElem.addEventListener("click", updateWebpageWithQuote); +updateWebpageWithQuote(); + // call pickFromArray with the quotes array to check you get a random quote From 0fe52e4c878d088d33870165c7e5aed0d7520caa Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Thu, 16 Jul 2026 15:06:22 +0100 Subject: [PATCH 2/3] html --- Sprint-3/quote-generator/index.html | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..c868c216e 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -5,11 +5,21 @@