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

Desmond Dallas
Desmond Dallas
6,985 Points

(upper)

Hi, can someone please explain the (upper) in this this function, on the first and second line. I understand the rest but:

1) why is the upper in the parenthesis? 2) Is this upper a condition and is it built within javascript? 3) Can the upper be name anything you wish, for example (up), (down) etc?

function randomNumber (upper) { return Math.floor( math.random() * upper) + 1; } var counter = 0; while ( counter < 10 ) { var randNum = randomNumber (6); document.write(randNum + ' '); counter += 1; }

2 Answers

Andrey Misikhin
Andrey Misikhin
16,529 Points
  1. Because it is argument of the function randomNumber. If function uses variable from outside of her body, than you must deliver this variable in function to use it inside.
  2. In this case upper is parameter, not a condition. Yes, this function written on JavaScript.
  3. You may use any name as you wish.
function printMessage(any) {
    console.log(any);
}
var myRealyCoolMessage = 'Hello World!';
printMessage(myRealyCoolMessage);