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 trialAssem Zhilkibayeva
5,717 PointsRandom numbers out of range
Here is code which I wrote:
function RandomNumber(upper, lower) {
var upper = prompt('Give an upper value'); var lower = prompt('Give a lower value'); return Math.floor(Math.random() * (upper - lower + 1)) + lower;
}
alert(RandomNumber());
The issue is that in the end answers are completely out of range which is given by upper and lower value
1 Answer
Steven Parker
231,236 PointsYour random formula is good, but you forgot to convert the strings from the prompt into numbers first. You can do this with parseInt.
Also, you should probably not declare the parameters in the function definition since the function would ignore them anyway.