In the following example, we use the
Math.random() function to get a pseudo-random number between 0 and 1. Then we multiply that value by
array.length to get a random value no greater than the size of the array. Finally, we used
Math.floor() that rounds down a given number.
random variable contains a random index of