JavaScript

Desmond Dallas
Desmond Dallas
4,704 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
14,850 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);