File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ // Function to fetch a random quote and update the DOM
2+ function displayRandomQuote ( ) {
3+ // 1. Get a random quote object using the provided helper function
4+ const randomQuote = pickFromArray ( quotes ) ;
5+
6+ // 2. Select the HTML elements where the quote and author will go
7+ const quoteElement = document . querySelector ( "#quote" ) ;
8+ const authorElement = document . querySelector ( "#author" ) ;
9+
10+ // 3. Update the text of those elements
11+ if ( quoteElement && authorElement ) {
12+ quoteElement . innerText = randomQuote . quote ;
13+ authorElement . innerText = randomQuote . author ;
14+ }
15+ }
16+
17+ // Ensure the DOM is fully loaded before attaching event listeners
18+ window . onload = function ( ) {
19+ // Display an initial quote right when the page loads
20+ displayRandomQuote ( ) ;
21+
22+ // Find the button and attach a click event listener
23+ const newQuoteBtn = document . querySelector ( "#new-quote" ) ;
24+ if ( newQuoteBtn ) {
25+ newQuoteBtn . addEventListener ( "click" , displayRandomQuote ) ;
26+ }
27+ } ;
28+
129// DO NOT EDIT BELOW HERE
230
331// pickFromArray is a function which will return one item, at
You can’t perform that action at this time.
0 commit comments