File tree Expand file tree Collapse file tree 3 files changed +22
-8
lines changed
Expand file tree Collapse file tree 3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
66 < title > Quote generator app</ title >
77 < script defer src ="quotes.js "> </ script >
8+ < link rel ="stylesheet " href ="style.css ">
89 </ head >
910 < body >
10- < h1 > Quote generator</ h1 >
11- < p id ="quote "> </ p >
12- < p id ="author "> </ p >
13- < button type ="button " id ="new-quote "> New quote</ button >
11+ < h1 > Quote Generator</ h1 >
12+ < p id ="quote "> </ p >
13+ < p id ="author "> </ p >
14+ < button type ="button " id ="new-quote "> New quote</ button >
15+ </ div >
1416 </ body >
1517</ html >
Original file line number Diff line number Diff line change 1414// Examples of use
1515// ---------------
1616// pickFromArray(['a','b','c','d']) // maybe returns 'c'
17-
17+ const quote = document . querySelector ( "#quote" ) ;
18+ const author = document . querySelector ( "#author" ) ;
19+ const newquote = document . querySelector ( "#new-quote" ) ;
1820// You don't need to change this function
19- function pickFromArray ( choices ) {
20- return choices [ Math . floor ( Math . random ( ) * choices . length ) ] ;
21+ function pickFromArray ( quotes ) {
22+ return quotes [ Math . floor ( Math . random ( ) * quotes . length ) ] ;
2123}
2224
2325// A list of quotes you can use in your app.
@@ -491,3 +493,14 @@ const quotes = [
491493] ;
492494
493495// call pickFromArray with the quotes array to check you get a random quote
496+ function showRandomQuote ( ) {
497+ const randomQuote = pickFromArray ( quotes ) ;
498+ quote . textContent = randomQuote . quote ;
499+ author . textContent = randomQuote . author ;
500+ }
501+ // show one on load
502+ showRandomQuote ( ) ;
503+ // change quote on click:
504+ quote . addEventListener ( "click" , showRandomQuote ) ;
505+ author . addEventListener ( "click" , showRandomQuote ) ;
506+ newquote . addEventListener ( "click" , showRandomQuote ) ;
Original file line number Diff line number Diff line change 1- /** Write your CSS in here **/
You can’t perform that action at this time.
0 commit comments