Skip to content

Commit 6100dc9

Browse files
author
russom
committed
showRandomQuote function implemented to display randomised quote upon page refresh or 'new quote' button click
1 parent 57bcdde commit 6100dc9

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎Sprint-3/quote-generator/quotes.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// pickFromArray(['a','b','c','d']) // maybe returns 'c'
1717

1818
// You don't need to change this function
19+
1920
function pickFromArray(choices) {
2021
return choices[Math.floor(Math.random() * choices.length)];
2122
}
@@ -490,4 +491,27 @@ const quotes = [
490491
},
491492
];
492493

494+
console.log(pickFromArray(quotes));
493495
// call pickFromArray with the quotes array to check you get a random quote
496+
497+
//When the page loads it should show a random quote from the `quotes` array on the screen. It should also show who said the quote.
498+
499+
//When you click a button on the screen it should change the quote on the screen.
500+
501+
const button = document.querySelector("#new-quote");
502+
const quoteText = document.querySelector("#quote");
503+
const quoteAuthor = document.querySelector("#author");
504+
505+
function showRandomQuote() {
506+
const randomQuote = pickFromArray(quotes);
507+
quoteText.textContent = randomQuote.quote;
508+
quoteAuthor.textContent = randomQuote.author;
509+
}
510+
511+
showRandomQuote();
512+
513+
button.addEventListener("click", showRandomQuote);
514+
515+
//function pickFromArray(choices) {
516+
// return choices[Math.floor(Math.random() * choices.length)];
517+
//}

0 commit comments

Comments
 (0)