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 trialMing Chi Wong
2,909 PointsUsing the function print(message);
I don't quite understand how the function print(message) work? I thought the variable message inside the parenthesis has to be declared before the function can be executed?
3 Answers
Seth Kroger
56,414 PointsWhen you define a function the parameters are automatically declared as variables within the function's body. There is no need to declare them separately.
Ming Chi Wong
2,909 PointsI meant from the exercise they did, they didn't define the variable message in the function print().
Adam Beer
11,314 PointsSimpliest way, just create a variable and give content to a string, like this
var myFirstPrint = "This is my first string when I learned how I can use print() method";
Now put your variable name into the print() method.
var myFirstPrint = "This is my first string when I learn how can use print() method";
print(myFirstPrint);
Print() method get a string, and print out your variable content. Hope this help!