Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<title>Quote generator app</title>
<script defer src="quotes.js"></script>
</head>
<body>
Expand Down
23 changes: 23 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,26 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
function pickFromArray(choices) {
return choices[Math.floor(Math.random() * choices.length)];
}

// Grab the quote and author elements
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");

// Function to display a random quote
function displayRandomQuote() {
const randomQuote = pickFromArray(quotes);
quoteElement.textContent = randomQuote.quote;
authorElement.textContent = randomQuote.author;
}

// Display a random quote when the page loads
displayRandomQuote();

// Grab the button element
const newQuoteButton = document.getElementById("new-quote");

// Change quote on button click
newQuoteButton.addEventListener("click", displayRandomQuote);