Skip to content

Commit c1fefff

Browse files
committed
fix: prevent multiple intervals by clearing existing timer before starting new one
1 parent 0cbfa1d commit c1fefff

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Sprint-3/quote-generator/quotes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,13 @@ let autoPlayInterval = null;
513513
autoPlayToggle.addEventListener("click", () => {
514514
if (autoPlayToggle.checked) {
515515
autoPlayStatus.innerText = "auto-play: ON";
516-
autoPlayInterval = setInterval(showRandomQuote, 4000);
516+
if (!autoPlayInterval) {
517+
autoPlayInterval = setInterval(showRandomQuote, 4000);
518+
}
517519
} else {
518520
autoPlayStatus.innerText = "auto-play: OFF";
519521
clearInterval(autoPlayInterval);
522+
autoPlayInterval = null;
520523
}
521524
});
522525

0 commit comments

Comments
 (0)