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.
I don't understand how the 'message' and 'list' parameters work
How does the function know what to put in for the value of the those parameters? Like 'message' isn't defined anywhere so how does it know what to display in document.write(message)? I'm just as confused with the 'list' parameter because I don't understand how it knows how long list.length is when it's not defined.
Yacine Diop3,465 Points
Think of this way:
- while writing the function, list is added as a parameter (I think of this as a placeholder); however, the intention for that space is for playlist later on.
- when we call the function to print, we now can place the var playList. This is our argument from the get go.
So while making the function, don't think list is not defined, instead the list will be defined later.
Same thing for document.write(message). Message is a placeholder, a parameter set into function print(message). We later called the function print(listHTML);
listHTML replaces the placeholder message.
This is how I think about it to make it clear to myself. Hope it helps someone.
Steven Parker210,424 Points
Parameters act as placeholders for the actual value that will be passed to the function when it is called.
You might think of a parameter as a variable that is declared by naming it in the function definition, and is automatically assigned when the function is called, getting set to the value supplied as the argument.
If a parameter is a list, the length of the list will be determined when the function is called and the real list is supplied as the argument.