+ 6

How do you output random numbers in JavaScript ?

16th May 2018, 12:22 PM
andrebtw
andrebtw - avatar
3 Answers
+ 6
//generates random no between 0 to 1 document.write(Math.random()); //generates random no between 0 to 1,whole no document.write(Math.floor(Math.random())); //generates random no between 1 to 10 //Math.random()*end+start document.write(Math.random()*10 +1); //generates random no between 11 to 20,whole no document.write(Math.floor( Math.random()* 20 +11)); https://code.sololearn.com/WBm9NED1fR9q/?ref=app
16th May 2018, 12:33 PM
Manorama
Manorama - avatar
+ 5
Math.random() returns a value between 0 and 1 (exclusive). Go figure.
16th May 2018, 12:33 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Thanks ;)
16th May 2018, 12:34 PM
andrebtw
andrebtw - avatar