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 trial
barak ben ishay
1,951 Pointswhy to return a value when you put an argument?
function getRandomNumber (upper) { return math.floor (math.random () * upper) + 1 ; }
in this function the value return random number let say 5000
the function shows 5000 why there is upper the the parentess (upper)? we alredy use the return statment to do so. thanke you!
1 Answer
Tsenko Aleksiev
3,819 PointsI think you got it a bit wrong. Math.random returns a random number allways between 0 ( inclusive ) and 1 ( exclusive ). The returned value is always lower than 1. This random number, for example 0.45 is than * to the number you want to be the max limit of your results again exclusive. If you use Math.random() * 10, you will get a random number between 0 and 9, if you use Math.random() * 100, you will get a random number between 0 and 99. So if you want a random number between 0 and 5000 and you want to have 5000 included as a posible result, upper in your function must be 5001. Your function is doing this: give me an upper limit of the numbers you want me to pick one random for you. Got it? :)