how to get a random whole number in javascript code example

Example 1: Generate random whole numbers javascript

var randomWholeNumber = Math.floor(Math.random() * 20);


function randomWholeNum() {

	return Math.floor(Math.random() * 10);

}

console.log(randomWholeNum());

Example 2: random number in js

Math.random() returns a random number in [0,1)

Example 3: math.floor + roandom

//Write the following code to get a random number between 1 and 10
       const result = Math.floor(Math.random()*(10)+ 1);