I have the following code:
var items = [item1, item2, item3];
var index = Math.random() * items.length;
I expect the statement
items[index]
to return a random item from my array, however it always returns undefined. How do I get the item indexed by the index variable?
Math.random()function returns a floating-point, pseudo-random number in the range 0–1 (inclusive of 0, but not 1)