Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRAVINDRA RAWAT
8,063 PointsPls check my code ...>>>> also What if the input number is zero " 0 " in the first step ?
Step 1 : var inputNum = parseInt( prompt("Please enter the bigger number"));
var randumNum = Math.floor ( Math.random () * inputNum) + 1 ;
alert("Result " + randumNum);
step 2 : var inputNum1 = parseInt( prompt("Please enter the bigger number")); var inputNum2 = parseInt( prompt("Please enter the smaller number"));
var randomNum = Math.floor(Math.random() * (inputNum1 - inputNum2 + 1) + inputNum2) ;
alert ("Result " + randomNum) ;
2 Answers
Steven Parker
231,275 PointsYour code performs similarly to the examples in the video.
In the first step, if the input number is 0 (or if it is 1), the output will always be 1.
RAVINDRA RAWAT
8,063 PointsThank you for the reply . How should we avoid this and generate random number even if the input is 0 or 1.?
Steven Parker
231,275 PointsBut the user is providing the limit for the range. An input of 0 or 1 limits the output to 1.
If you want to ignore the user's input, what range would you want to use?