From de4c0ee384432e1d52da68b4868b4a89f49ffed2 Mon Sep 17 00:00:00 2001 From: Nahom Mesfin Date: Sun, 17 Aug 2025 22:39:08 +0100 Subject: [PATCH 1/2] add html title --- Sprint-3/quote-generator/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..5f6a720f1 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -3,7 +3,7 @@ - Title here + Quote generator app From 719abd42a157fb7dd589d2b0b0ee790eb15c1b93 Mon Sep 17 00:00:00 2001 From: Nahom Mesfin Date: Sun, 17 Aug 2025 22:39:33 +0100 Subject: [PATCH 2/2] quote generator function buildup --- Sprint-3/quote-generator/quotes.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..d129a8454 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -491,3 +491,26 @@ const quotes = [ ]; // call pickFromArray with the quotes array to check you get a random quote +function pickFromArray(choices) { + return choices[Math.floor(Math.random() * choices.length)]; +} + +// Grab the quote and author elements +const quoteElement = document.getElementById("quote"); +const authorElement = document.getElementById("author"); + +// Function to display a random quote +function displayRandomQuote() { + const randomQuote = pickFromArray(quotes); + quoteElement.textContent = randomQuote.quote; + authorElement.textContent = randomQuote.author; +} + +// Display a random quote when the page loads +displayRandomQuote(); + +// Grab the button element +const newQuoteButton = document.getElementById("new-quote"); + +// Change quote on button click +newQuoteButton.addEventListener("click", displayRandomQuote); \ No newline at end of file