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

Ming Chi Wong
Ming Chi Wong
1,049 Points

Using 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
MOD
Seth Kroger
Treehouse Moderator 56,263 Points

When 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
Ming Chi Wong
1,049 Points

I meant from the exercise they did, they didn't define the variable message in the function print().

Adam Beer
Adam Beer
11,268 Points

Simpliest 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!