I’ve finally finished the basic functionality of my quote machine, but I have a problem which I haven’t been able to solve. I can’t seem to find a solution in the forum or elsewhere either. The code works ok, but sometimes the quote won’t load. This happens both at page load/refresh, and on button click. Could anyone help me figure this out? I realize that we should probably use an API for this, and that will be my next task, but I would still like to understand why this is happening.
Shouldn’t this be var randNumber=Math.floor(Math.random()*quotes.length/2);?
Next you use quotes[randNumber*2], which overshoots the length of quotes in certain cases (when Math.random()>0.5).
You seem to have your quotes stored in an array, so I guess the bug comes from JS giving you the same random number, thus showing you the same quote.
P.S.
Don’t get me wrong but I think the goal of Random Quote Machine project was to learn how to get data using AJAX request, instead of writing the quotes yourself.
There’s no such requirement. There’re only 2 requirements which are clearly stated in challenge description. (and remember, you’re not supposed to look at example project’s code)