Random Quote Machine Question~

Random Quote Machine Question~
0.0 0


I am having trouble getting the quote to appear on the screen. I was wondering if someone could point me in the right direction of what I need to correct. Here is my pen:

Thank you.


In your showQuote function, you have the following line:

var quote = list.getRandom(0, list.length);

list is an array. JavaScript has built in functions for working with arrays which you have already learned (i.e. join, indexOf, pop, push, shift, slice, splice, concat, etc…). You can not create a simple function and then just apply it to your array they way you are trying to do it.

Without going into a more advanced solution here, you can simply use a slightly modified version of your getRandom function to generate an integer between 0 and 1 less than your list’s length. Your current getRandom will actually produce an integer between 0 and the list’s length, which will not work, because arrays are zero-indexed. To correct, get rid of the + 1 in the (max - min + 1).

Then in your showQuote function you want to create a new variable and assign the result of calling the getRandom function. This randomNum variable represents an index of your list array. Now, you just need to remember how to access an element of an array with an index by making use of the randomNum variable. I will let you review that part on your own.

This should be enough to get you back on track with your project.

Happy coding!