Skip to content
Sign upLog in
← Back to Community

Random Number in JavaScript

Profile icon
ruiwenge2

How do I get a random number between 10 and 20 in js using Math.random?

Answered by Bunnytoes [earned 5 cycles]
View Answer
Voters
Profile icon
DeanLentz
Profile icon
ruiwenge2
Comments
hotnewtop
Profile icon
Bunnytoes
Profile icon
VulcanWM

Use the code below:

Math.floor(Math.random() * 20) + 10;

Profile icon
ruiwenge2

@VulcanWM
wait no its actually Math.floor(Math.random() * 10) + 10

Profile icon
VulcanWM

oh yeah i thought u meant 1 to 20 sorry

@ruiwenge2