Random in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Random in JavaScript

Is there a way to generate random numbers in JavaScript? If so, please tell me how.

29th Jun 2019, 8:47 PM
Pikachu
Pikachu - avatar
1 Answer
+ 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
29th Jun 2019, 8:51 PM
Airree
Airree - avatar