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 Tracking Multiple Items with Arrays Using For Loops with Arrays

Pablo Calvo
Pablo Calvo
13,044 Points

Guys,... im having trouble understanding where does the "message" variable comes into play here... it is not defined...

where is the "message" defined..?

The function print is actualy not nessesary. "function print(message) { document.write(message); }" You can use it to print or you can use document.write() method as well with out function.

3 Answers

Steven Parker
Steven Parker
231,275 Points

Parameters are defined simply by naming them in the function definition:

function print(message) {  // <-- this defines "message" as a parameter
Pablo Calvo
Pablo Calvo
13,044 Points

Think I get it now Steven thanks for replying.

Steven Parker
Steven Parker
231,275 Points

Pablo Calvo — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!

Mikeal Mann
seal-mask
.a{fill-rule:evenodd;}techdegree
Mikeal Mann
Full Stack JavaScript Techdegree Student 17,913 Points

Hey Steven,

This is from w3school and it helped me understand it better:

The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value. Changes to arguments are not visible (reflected) outside the function.

Basically, you can call the parameter whatever you desire. Just make sure that it makes sense to your future self when you come back to your code days later :) The variable could have been called text, message, sentence, cat etc.

Cheers, Mikey

Steven Parker
Steven Parker
231,275 Points

The part about "not changing the original value" only applies to primitive types. If an argument is an array, for example, the function can make permanent changes to the array contents that are visible outside the function.