0

What is the command for producing a random value out of a set of available values?

Please help.

20th Jun 2017, 4:38 PM
Ben Galbraith
2 Answers
0
store all your variables you want into an array. use alert or console.log, with the random function to go from 0, to the array length - 1. this will randomly show a value from any of the variables you stored into the array.
20th Jun 2017, 4:52 PM
Welliton Malta
Welliton Malta - avatar
0
return a number between 1 & 100: >>> Math.floor((Math.random() * 100) + 1); return a number between 50 & 150: >>> Math.floor((Math.random() * 100) + 50); *Note:: Math.random ALWAYS returns a number between 0 and 1
20th Jun 2017, 8:39 PM
Mat
Mat - avatar