Skip to content

Commit 12275cc

Browse files
committed
removed document.getElementById outside the function
1 parent d9cc099 commit 12275cc

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,19 +490,22 @@ const quotes = [
490490
},
491491
];
492492

493+
const quoteParagraph = document.getElementById("quote");
494+
const authorParagraph = document.getElementById("author");
495+
const button = document.getElementById("new-quote");
496+
497+
// call pickFromArray with the quotes array to check you get a random quote
498+
function showRandomQuote() {
499+
let randomQuote = pickFromArray(quotes);
500+
updateUI(randomQuote);
501+
}
502+
493503
function updateUI(quoteObject) {
494-
let quoteParagraph = document.getElementById("quote");
495504
quoteParagraph.innerText = quoteObject.quote;
496-
let authorParagraph = document.getElementById("author");
497505
authorParagraph.innerText = quoteObject.author;
498506
}
499507

500-
// call pickFromArray with the quotes array to check you get a random quote
501-
let randomQuote = pickFromArray(quotes);
502-
updateUI(randomQuote);
503-
504-
const button = document.getElementById("new-quote");
505508
button.addEventListener("click", () => {
506-
const newQuoteObject = pickFromArray(quotes);
507-
updateUI(newQuoteObject);
509+
showRandomQuote();
508510
});
511+
showRandomQuote();

0 commit comments

Comments
 (0)