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 diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..c5f169195 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -1,3 +1,22 @@ +// call pickFromArray with the quotes array to check you get a random quote +function displayRandomQuote() { + const quoteP = document.getElementById("quote"); + const authorP = document.getElementById("author"); + + const selectedQuote = pickFromArray(quotes); + + quoteP.textContent = selectedQuote.quote; + authorP.textContent = selectedQuote.author; +} + +// Setup event listener and display initial quote on load +window.addEventListener("DOMContentLoaded", () => { + displayRandomQuote(); + + const newQuoteBtn = document.getElementById("new-quote"); + newQuoteBtn.addEventListener("click", displayRandomQuote); +}); + // DO NOT EDIT BELOW HERE // pickFromArray is a function which will return one item, at @@ -489,5 +508,3 @@ const quotes = [ author: "Zig Ziglar", }, ]; - -// call pickFromArray with the quotes array to check you get a random quote