File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 < head >
44 < meta charset ="UTF-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6- < title > Title here </ title >
6+ < title > Quote generator app </ title >
77 < script defer src ="quotes.js "> </ script >
88 </ head >
99 < body >
10- < h1 > hello there </ h1 >
11- < p id ="quote "> </ p >
12- < p id ="author "> </ p >
10+ < h1 > Quote Generator </ h1 >
11+ < p id ="quote "> Quote: </ p >
12+ < p id ="author "> Author: </ p >
1313 < button type ="button " id ="new-quote "> New quote</ button >
1414 </ body >
1515</ html >
Original file line number Diff line number Diff line change @@ -491,3 +491,19 @@ const quotes = [
491491] ;
492492
493493// call pickFromArray with the quotes array to check you get a random quote
494+ console . log ( pickFromArray ( quotes ) ) ;
495+
496+ // 1. get a button variable.
497+ // 2. listen to the event.
498+ // 3, when event happens produce a quote in one place <p>
499+ //4. when an event happens produce author of that quote in the other <p>
500+ const button = document . querySelector ( "#new-quote" ) ;
501+ function newQuoteEveryTime ( ) {
502+ const quote = pickFromArray ( quotes ) ;
503+ const quotePlace = document . querySelector ( "#quote" ) ;
504+ const authorPlace = document . querySelector ( "#author" ) ;
505+ quotePlace . innerText = `The quote of the day is: ${ quote . quote } ` ;
506+ authorPlace . innerText = `By the author - ${ quote . author } ` ;
507+ }
508+
509+ button . addEventListener ( "mousedown" , newQuoteEveryTime ) ;
You can’t perform that action at this time.
0 commit comments