File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -492,9 +492,13 @@ const quotes = [
492492
493493// call pickFromArray with the quotes array to check you get a random quote
494494
495- const quoteElement = document . getElementById ( "quote" ) ;
495+ // this runs when the page loads
496+
497+ function setup ( ) {
498+ const quoteElement = document . getElementById ( "quote" ) ;
496499const authorElement = document . getElementById ( "author" ) ;
497500
501+
498502function displayQuote ( ) {
499503 const randomQuote = pickFromArray ( quotes ) ;
500504
@@ -508,4 +512,8 @@ displayQuote();
508512// Change quote when button is clicked
509513document
510514 . getElementById ( "new-quote" )
511- . addEventListener ( "click" , displayQuote ) ;
515+ . addEventListener ( "click" , displayQuote ) ;
516+ }
517+
518+ // run setup after page loads
519+ window . addEventListener ( "load" , setup ) ;
You can’t perform that action at this time.
0 commit comments