Ask coding questions

← Back to all posts
Random Number in JavaScript
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
ruiwenge2
Comments
hotnewtop
Bunnytoes
VulcanWM

Use the code below:

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

ruiwenge2

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

VulcanWM

oh yeah i thought u meant 1 to 20 sorry @ruiwenge2