+ 1
How can I use user input to create a random generating number in html/javascript?
Hello I am trying to get user input of a high number (Num2) and a low number (Num1) and pick a random number in between those numbers if anyone knows how please tell me...
4 Answers
+ 2
var minNum = prompt("Please enter min num: ", "0");
var maxNum = prompt("Please enter max num: ", "10");
var randNum = getRandom(minNum, maxNum);
alert("Your result is " + randNum);
function getRandom(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
+ 2
thanks it worked
+ 2
thanks
+ 1
You're welcome. Best of luck to you.