JavaScript program to take a max limit from user and generate a random number till that number

Views: 110   

Following program shows you how to take a max limit from user and generate a random number till that number.
In this program we get max limit number from user and generate a random number using Math.random()

var maxLimit = prompt("Enter maxlimit to generate a random number:")
var result = Math.floor((Math.random() * maxLimit) + 1);
console.log("Random number is: " + result);

Output:

Enter maxlimit to generate a random number:
100
Random number is: 65
On By