The following function SHOULD generate a random number between the range of max and min. And it does, when I pass numbers directly in the argument.
function randomIntFromRange(min,max)
{
return Math.floor(Math.random() * (max - min + 1) + min);
}
However when I take input from HTML form, it doesn't generate random value between max and min, rather it generates a random value between 0 and max-min.
Am I doing some obvious stupid mistake? Please help.
var num = 100;
function randomIntFromRange(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function trial() {
num = randomIntFromRange(document.getElementById("a1").value, document.getElementById("a2").value)
console.log(num);
}
<input id="a1" type="text" value="100">
<input id="a2" type="text" value="150">
<button onclick="trial()">click</button>