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,11 +492,19 @@ const quotes = [
492492
493493// call pickFromArray with the quotes array to check you get a random quote
494494
495- const quoteEl = document . getElementById ( "quote" ) ;
496- const authorEl = document . getElementById ( "author" ) ;
497- const newQuoteBtn = document . getElementById ( "new-quote" ) ;
498- const autoPlayToggle = document . getElementById ( "auto-play-toggle" ) ;
499- const autoPlayStatus = document . getElementById ( "auto-play-status" ) ;
495+ function getElement ( id ) {
496+ const element = document . getElementById ( id ) ;
497+ if ( ! element ) {
498+ throw new Error ( `Element with id "${ id } " not found in the HTML` ) ;
499+ }
500+ return element ;
501+ }
502+
503+ const quoteEl = getElement ( "quote" ) ;
504+ const authorEl = getElement ( "author" ) ;
505+ const newQuoteBtn = getElement ( "new-quote" ) ;
506+ const autoPlayToggle = getElement ( "auto-play-toggle" ) ;
507+ const autoPlayStatus = getElement ( "auto-play-status" ) ;
500508
501509newQuoteBtn . addEventListener ( "click" , showRandomQuote ) ;
502510
You can’t perform that action at this time.
0 commit comments