From 97542facdeae830cca9efb62afee655a8a79b901 Mon Sep 17 00:00:00 2001 From: Zadri Abdule Date: Tue, 28 Jul 2026 16:07:07 +0100 Subject: [PATCH 1/2] update title in index.html --- Sprint-3/quote-generator/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..befe8788e 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -1,9 +1,9 @@ - + - Title here + Quote generator app From 2c28b5aeb3cf10a03d3d3f91d1d57c46af81ca6a Mon Sep 17 00:00:00 2001 From: Zadri Abdule Date: Tue, 28 Jul 2026 18:12:37 +0100 Subject: [PATCH 2/2] complete quote generator app task --- Sprint-3/quote-generator/package.json | 2 +- Sprint-3/quote-generator/quotes.js | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Sprint-3/quote-generator/package.json b/Sprint-3/quote-generator/package.json index 0f6f98917..3f5126ba6 100644 --- a/Sprint-3/quote-generator/package.json +++ b/Sprint-3/quote-generator/package.json @@ -2,7 +2,7 @@ "name": "quote-generator", "version": "1.0.0", "license": "CC-BY-SA-4.0", - "description": "You must update this package", + "description": "Simple quote generator that picks a quote at random", "scripts": { "test": "jest --config=../jest.config.js quote-generator" }, diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..1212e2152 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -1,5 +1,38 @@ // DO NOT EDIT BELOW HERE +document.addEventListener("DOMContentLoaded", () => { + const quoteEl = document.getElementById("quote"); + const authorEl = document.getElementById("author"); + const newQuoteBtn = document.getElementById("new-quote"); + if (!quoteEl || !authorEl || !newQuoteBtn) { + console.warn("Missing #quote, #author or #new-quote element."); + return; + } + let lastIndex = -1; + + function showRandomQuote() { + let index; + + if (quotes.length === 1) { + index = 0; + } else { + do { + index = Math.floor(Math.random() * quotes.length); + } while (index === lastIndex); + } + + lastIndex = index; + + const chosen = quotes[index]; + + quoteEl.textContent = `"${chosen.quote}"`; + authorEl.textContent = `— ${chosen.author}`; + } + + showRandomQuote(); + + newQuoteBtn.addEventListener("click", showRandomQuote); +}); // pickFromArray is a function which will return one item, at // random, from the given array. //