diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcfb..4b8da3d6e6 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -1,10 +1,11 @@ - + - Title here + Quote generator app +

hello there

diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b722..8f6b19fa32 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -491,3 +491,41 @@ const quotes = [ ]; // call pickFromArray with the quotes array to check you get a random quote + +const quoteElement = document.querySelector("#quote"); +const authorElement = document.querySelector("#author"); +const newQuoteButton = document.querySelector("#new-quote"); + +// function displayRandomQuote() { +// const randomQuote = pickFromArray(quotes); +// quoteElement.textContent = randomQuote.quote; +// authorElement.textContent = randomQuote.author; +// } + +const AUTO_INTERVAL_MS = 6000; +let autoQuoteInterval = null; + +function displayRandomQuote() { + const randomQuote = pickFromArray(quotes); + quoteElement.textContent = randomQuote.quote; + authorElement.textContent = randomQuote.author; +} + +function startAutoQuotes(fetchFn) { + if (autoQuoteInterval) { + clearInterval(autoQuoteInterval); + } + autoQuoteInterval = setInterval(() => { + fetchFn(); + }, AUTO_INTERVAL_MS); +} + +// Display an initial random quote when the page loads +displayRandomQuote(); +startAutoQuotes(displayRandomQuote); + +// Display a new quote on click and reset the auto-timer +newQuoteButton.addEventListener("click", () => { + displayRandomQuote(); + startAutoQuotes(displayRandomQuote); +}); diff --git a/Sprint-3/quote-generator/style.css b/Sprint-3/quote-generator/style.css index 63cedf2d2f..38b274816b 100644 --- a/Sprint-3/quote-generator/style.css +++ b/Sprint-3/quote-generator/style.css @@ -1 +1,52 @@ /** Write your CSS in here **/ +*, +*::before, +*::after { + box-sizing: border-box; + margin: 0; + padding: 0; +} + +body { + max-width: 48rem; + padding: 2rem; + font-family: + system-ui, + -apple-system, + BlinkMacSystemFont, + "Segoe UI", + sans-serif; + background: #ffffff; + color: #111827; + line-height: 1.5; +} + +h1 { + margin-bottom: 1rem; + font-size: 2rem; +} + +#quote { + margin-bottom: 0.75rem; + font-size: 1.2rem; +} + +#author { + margin-bottom: 1.5rem; + color: #4b5563; + font-style: italic; +} + +#new-quote { + padding: 0.55rem 1.1rem; + border: 1px solid #d1d5db; + border-radius: 0.4rem; + background: #888; + color: #111827; + font-size: 0.95rem; + cursor: pointer; +} + +#new-quote:hover { + background: #ffffff; +}