0
What is the command for producing a random value out of a set of available values?
Please help.
2 Antworten
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.
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