I am trying to loop over an array of objects and display a random quote from the data, so far my code returns undefined. Any idea's why?
Code so far..
const quotesToUse = [{
quote: "This was the biggest quote ever - Array Object",
author: "Derek Bullshido",
},
{
quote: "Hey hows it going - Array Object",
author: "Paul Frank",
},
{
quote: "Why can I say that - Array Object",
author: "Derek Paul",
},
]
function randomQuotes() {
for (var i = 0; i < 1; i += 1 ) {
const randomQuote = quotesToUse[i][Math.floor(Math.random() * quotesToUse[i].quote.length)];
document.getElementById("container").appendChild(text).append(randomQuote);
}
I am trying to display the quote (String) randomly.
for (var i = 0; i < 1; i += 1 )? That's the same as var i = 0;