How can I use user input to create a random generating number in html/javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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...

13th Nov 2017, 3:06 PM
BrotatoBoi
BrotatoBoi - avatar
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; }
13th Nov 2017, 3:15 PM
AgentSmith
+ 2
thanks it worked
13th Nov 2017, 3:17 PM
BrotatoBoi
BrotatoBoi - avatar
+ 2
thanks
13th Nov 2017, 3:21 PM
BrotatoBoi
BrotatoBoi - avatar
+ 1
You're welcome. Best of luck to you.
13th Nov 2017, 3:21 PM
AgentSmith