Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Pablo Calvo
Pablo Calvo
7,812 Points

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

where is the "message" defined..?

anywayiam
anywayiam
3,731 Points

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
210,424 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
7,812 Points

Think I get it now Steven thanks for replying.

Steven Parker
Steven Parker
210,424 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,616 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
210,424 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.