Skip to content

Commit 828dc03

Browse files
Fix null checks for quote and author elements and refactor interval variable for auto-generate functionality
1 parent 405bec9 commit 828dc03

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Sprint-3/quote-generator/quotes.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,13 @@ function chooseQuote() {
496496
const randomQuote = pickFromArray(quotes)
497497

498498
const quote = document.getElementById("quote");
499+
if(quote!==null){
499500
quote.innerText = randomQuote.quote;
500-
501+
}
501502
const author = document.getElementById("author");
503+
if(author!==null){
502504
author.innerText = randomQuote.author;
505+
}
503506
}
504507

505508
window.addEventListener("load", chooseQuote);
@@ -510,8 +513,9 @@ button.addEventListener("click", chooseQuote);
510513
const autoGenerate = document.getElementById("auto-play-toggle");
511514
let interval = null;
512515
autoGenerate.addEventListener("change", () => {
516+
let changeQuoteInterval=2000
513517
if (autoGenerate.checked) {
514-
interval = setInterval(chooseQuote, 2000);
518+
interval = setInterval(chooseQuote, changeQuoteInterval);
515519
} else {
516520
clearInterval(interval);
517521
interval = null;

0 commit comments

Comments
 (0)