How to generate a random number between two numbers in JavaScript

The easiest way to randomly choose a number between two

In conjunction withMath.floor()withMath.random().

This simple line of code will return you numbers between 1 and 6 (all inclusive):

Math.floor(Math.random() * 6 + 1)

There are 6 possible outcomes: 1, 2, 3, 4, 5, 6.

Download mine for freeJavaScript beginner's manual


More js tutorials: