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

JavaScript JavaScript Functions Pass Information Into Functions Function Parameters and Arguments

upper and 6?

In this teaching video i dont see what upper and 6 are doing they seem irrelavent?

3 Answers

Hi, upper is controlling how high the random number can be, by multiplying the result of Math.random() (which generates a random number between 0 and 1) by itself, then rounding the result down. That's basically the same as the first example where Math.random() was always multiplied by 6, except now you can change what it multiplies Math.random() by by changing the argument you pass in when you call the function. Hope this helped!

god bless this comment. makes so much sense and I understand it more. thank you

Thanks for your answer, I kept reading it over and over... I found one sentence that in particular helped:-

PARAMETER VARIABLES ARE USED TO IMPORT ARGUMENTS INTO FUNCTIONS.

This sits printed out above my computer screens.

No problem!

function getRandomNumber(upper) { const randomNumber = Math.floor(Math.random() * upper) + 1; return randomNumber; }

console.log(getRandomNumber(6));

why when passing 6, it generates a number lower than 6?

6 is the value passed to the argument, the current limit of the program are from 1 - 6, and so the program wont go above 6, try submitting 100 instead of 6 and youll find it wont exceed 100!
console.log(getRandomNumber(100));