diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..ef7d5183d 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -3,7 +3,7 @@ - Title here + Quote generator app @@ -11,5 +11,6 @@

hello there

+ diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..e2e4f1a97 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -1,3 +1,4 @@ + // DO NOT EDIT BELOW HERE // pickFromArray is a function which will return one item, at @@ -491,3 +492,29 @@ const quotes = [ ]; // call pickFromArray with the quotes array to check you get a random quote +function pickAndDisplayQuote() { + const randomQuote = pickFromArray(quotes); + //console.log(randomQuote); + document.getElementById("quote").textContent = randomQuote.quote; + document.getElementById("author").textContent = randomQuote.author; +} + +document.getElementById("new-quote").addEventListener("click", () => { + pickAndDisplayQuote(); +}); +let intervalId; +document.getElementById("auto-play").addEventListener("change",(event)=>{ + if (event.target.checked){ + //console.log("auto-play is on"); + document.getElementById("auto-play-label").textContent = "auto-play : ON"; + intervalId=setInterval(pickAndDisplayQuote,5000); + }else{ + document.getElementById("auto-play-label").textContent = "auto-play : OFF"; + clearInterval(intervalId); + } +}); + + + + +window.onload = pickAndDisplayQuote; \ No newline at end of file