I am working on a random quote generator, where I first randomly generate a number between 0 and the length of the array 'quotes,' then return that quote.
function getQuote() {
var quotes = ["I never met a toby that I didn't like ~ Kimya Dawson", "Blood in my beard ~ Aesop Rock", "How many roads must a man walk down? ~ Bob Dylan", "Orange is the new black ~ Jenji Kohan"];
function randomNumber(min, max) {
var quote = Math.floor(Math.random() * (max - min +1)) + min
return quotes[quote];
};
return randomNumber(0, quotes.length);
};
getQuote();
It works most of the time, but every so often it will return 'Undefined.' I did not have this problem when testing with an array of single words like 'hello,' 'green,' etc., it only happens when I add spaces.