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 trialMustafa Malik
Courses Plus Student 1,491 Pointswhen you call a function, you pass that function one or more____??? what is the answer
i can't get the answer right.
6 Answers
Ognjen Jevremovic
13,028 PointsHello Mustafa, how are you? The answer I think you're looking for is "arguments" = ).
You see when you make a function, you can define as low as one (or either none, if that's the case) up to as many number of parameters as you like. So for example:
function RNG(minValue, maxValue) {
return Math.floor( Math.random() * (maxValue - minValue + 1 ) + minValue;
}
The above example is just a simple (vanilla - pure JS code) function that returns a random number generated between the two numbers.
The parameter acts just as a variable, that can only be used inside of that function scope. Meaning that minValue
and maxValue
"variables" (actually they are called parameters of RNG function, but as I said they just act as variables inside of that function code block).
The values that you pass in to a function, that get stored inside of the parameters defined, are called arguments (the answer to your question).
So, by calling the function defined above and by passing it two number arguments like this:
RNG(5, 25);
Will generate (and return to that same line) the random number generated between the number range (from 5 to 25 - including those aswell).
Hope that helps! All the best
Brian Holland
3,508 PointsI would have to say 'argument(s)', but that seems like it should be in the video material.
Caleb Kleveter
Treehouse Moderator 37,862 PointsThe parentheses mess up the answer, if you leave them out it should pass.
Gary Calhoun
10,317 PointsFrom my understanding once you create a function, you only have to call it once for it to be registered by the interpreter as a function.
Gary Calhoun
10,317 PointsSorry I misunderstood the question, yes you pass arguments through a function and it can be more than one argument Brian is correct.
shang jiang
Courses Plus Student 5,830 PointsWhen you call a function, the pieces of information being passed to that function are called:
parameter and variable is incorrect.
so the correct answer probably either string or argument.
Mustafa Malik
Courses Plus Student 1,491 PointsThank you very much guys. You people have been a great help. :)