0

How can i generate 5 random numbers between 1 and 6 in JavaScript. Math.Random only generates 1 number per time.

14th May 2019, 6:20 PM
Bolaji Olayinka
Bolaji Olayinka - avatar
12 Réponses
+ 7
function display() { let min = 1 , max = 6 document.write(Math.floor(Math.random() * 10 % ((max - min) + min)) + 1) document.write("<br>") } for(let i = 0; i < 5; i++) { display() } Displays from 1 to 6
14th May 2019, 7:04 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 11
Bolaji Olayinka Hi, dont be so mad. ~ swim ~ gave you more than a plain answer. He told you the way of doing this ;> Also bear in mind he's not the one who wants to show off :)
14th May 2019, 6:53 PM
r8w9
r8w9 - avatar
+ 1
I would use a loop to generate 5 different random numbers. It's the simplest way, even though there's likely more streamlined and complex ways
14th May 2019, 6:34 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 1
here you did not ask me, and I will answer you https://code.sololearn.com/Wr3ZSJjKMZHP/?ref=app
14th May 2019, 7:03 PM
Kirill Shlenkin
Kirill Shlenkin - avatar
0
Thanks, but i dont know how to
14th May 2019, 6:24 PM
Bolaji Olayinka
Bolaji Olayinka - avatar
0
~ swim ~ var intelligence ="stupid"; for (var i=0; i<=3; i++){ console.log("not" + "" + "intelligence") }
14th May 2019, 6:40 PM
Bolaji Olayinka
Bolaji Olayinka - avatar
- 1
Thanks for your time, the fact that u know something doesnt give u a privilege of talking down on newbies. pls give room for people to answer my question
14th May 2019, 6:35 PM
Bolaji Olayinka
Bolaji Olayinka - avatar
- 2
I dont think u need to comment, what u gave isnt an answer, it is not needed. I know how to loop, but i havent looped through random nums before
14th May 2019, 6:28 PM
Bolaji Olayinka
Bolaji Olayinka - avatar