diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..3705dadea 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -3,11 +3,11 @@ - Title here + Quote Generator App -

hello there

+

Random Quote:

diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..202e72ce4 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -491,3 +491,32 @@ const quotes = [ ]; // call pickFromArray with the quotes array to check you get a random quote + +function showNewQuote() { + updateQuote(); + replaceQuote(); +} + +const state = { + quote: "", + author: "", +}; + +function updateQuote() { + const chosenQuote = pickFromArray(quotes); + state.quote = chosenQuote.quote; + state.author = chosenQuote.author; +} + +function replaceQuote() { + const quoteElem = document.getElementById("quote"); + const authorElem = document.getElementById("author"); + quoteElem.textContent = state.quote; + authorElem.textContent = state.author; +} + +document.getElementById("new-quote").addEventListener("click", function () { + showNewQuote(); +}); + +window.onload = showNewQuote;