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 Loops, Arrays and Objects Simplify Repetitive Tasks with Loops A Closer Look at Loop Conditions

Nicholas Wallen
Nicholas Wallen
12,278 Points

Why is upper put in the parenthesis at the top of the code?

I understand what the whole code does, just not that specific part:

var upper = 10000; var randomNumber = getRandomNumber(upper); var guess; var attempts = 0;

Explain like I am 5 what using upper as the argument does.

1 Answer

Steven Parker
Steven Parker
229,786 Points

Any time you call a function, you put parentheses after the name. if the function requires one or more arguments, they are put inside those parentheses.

In this case, the "upper" argument given to "getRandomNumber" determines the upper limit on the random number that is returned by the function.

Nicholas Wallen
Nicholas Wallen
12,278 Points

LOL, so I get what you said, but then can you explain this:

var randomNumber = getRandomNumber(10); var guess; var guessCount = 0;

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

Steven Parker
Steven Parker
229,786 Points

I just answered that question separately. Arguments can be passed as variables or as literals.