samedi 24 octobre 2020

How do I make a random quote generator not repeat quotes

I've searched the site for answers but the one's that come up aren't similar/specific to the code that I have written. I don't know how to modify the code so that the quotes don't repeat when the user presses a button to generate another quote.

var quotes = [
{
    quote: "\"Don't just exist, live\""
},
{
    quote: "\"Try to be a rainbow in someone's cloud\""
},
{
    quote: "\"Prove them wrong\""
},
{
    quote: "\"Find reasons to smile\""
},
{
    quote: "\"You get what you give\""
}
]

var quotebtn = document.getElementById('quote-btn');
var quote = document.querySelector('.quote');

quotebtn.addEventListener('click', () => {
let random = Math.floor(Math.random() * quotes.length);

quote.innerHTML = quotes[random].quote;
})



Aucun commentaire:

Enregistrer un commentaire