+ 2
How to get a random number in JavaScript
I want to make a math game involving random numbers but I don't know how to get random numbers. If that is not possible how to select from an array?
1 Answer
+ 5
--Random number: (between 0 and 1)
Math.random()
--Random number between 0 and what number you want:
Math.floor(Math.random()*your number)
--Random element from array:
array[Math.floor(Math.random()*array.length)]