Skip to content

Commit be903f2

Browse files
Add auto-play functionality to display quotes at intervals
1 parent 0015e40 commit be903f2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Sprint-3/quote-generator/quotes.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,25 @@ button.addEventListener("click", () => {
510510
const author = document.getElementById("author");
511511
author.innerText = randomQuote.author;
512512
});
513+
514+
function chooseQuote(){
515+
const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
516+
517+
const quote = document.getElementById("quote");
518+
quote.innerText = randomQuote.quote;
519+
520+
const author = document.getElementById("author");
521+
author.innerText = randomQuote.author;
522+
}
523+
const autoGenerate = document.getElementById("auto-play-toggle");
524+
let interval = null;
525+
autoGenerate.addEventListener("change",()=>{
526+
527+
if(autoGenerate.checked){
528+
interval=setInterval(chooseQuote,2000)
529+
}else{
530+
clearInterval(interval)
531+
interval=null
532+
}
533+
})
534+

0 commit comments

Comments
 (0)