Skip to content

Commit 149b2c4

Browse files
committed
Add functionality to display and update random quotes on button click
1 parent ecba3c6 commit 149b2c4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sprint-3/quote-generator/quotes.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,19 @@ const quotes = [
496496
const quoteElement = document.getElementById("quote");
497497
const authorElement = document.getElementById("author");
498498
const buttonElement = document.getElementById("new-quote");
499+
500+
function displayRandomQuote() {
501+
// get a random quote from the quotes array
502+
const randomQuote = pickFromArray(quotes);
503+
504+
// update the quote and author elements
505+
quoteElement.textContent = randomQuote.quote;
506+
authorElement.textContent = randomQuote.author;
507+
}
508+
509+
displayRandomQuote(); // display a random quote when the page loads
510+
511+
// display a new random quote when button is clicked
512+
buttonElement.addEventListener("click", () => {
513+
displayRandomQuote();
514+
});

0 commit comments

Comments
 (0)