+ 2
Random in JavaScript
Is there a way to generate random numbers in JavaScript? If so, please tell me how.
1 Antwort
+ 7
Yes. There is a function, Math.random. It creates a pseudo-random number between 0 (inclusive) and 1 (exclusive). To make a random intiger, you can do something like this:
Math.floor(Math.random() * 10)
This will generate a random number between 0 and 9