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 trialasia flowers
2,496 Pointshello im confused it says make sure im calling the greet function. am i calling it correctly?
function greet = (val) => {
return `Hi, ${val}!`
};
greet = 'cool coders';
2 Answers
Jordan Laursen
10,465 PointsI see in your comment when calling greet that you had a space between greet and your opening parenthesis
greet ('cool coders');
// The space between greet and the parenthesis is producing a syntax error I'm assuming
// Should be
greet('cool coders');
// No space
Juan Luna Ramirez
9,038 PointsYou have to use ()
if you want to call a function. This greet function accepts an argument val
, so in order to call it you can do greet('cool coders')
. If the greet function did not accept an argument then it would have just been greet()
. The part that tells your program to actually run the function is having the parentheses.
Also, you have to save the function to a variable if you want to use an arrow function and call that function yourself as you are doing here.
You can save functions to variables. One way is like this:
const greet = function (val) {
return `Hi, ${val}!`
};
greet('cool coders');
So the final result when using an arrow function is:
const greet = (val) => {
return `Hi, ${val}!`
};
greet('cool coders');
asia flowers
2,496 Pointsthank you. i have it exactly how you have shown in the second example and it is giving the same message for some reason.
const greet = (val) => {
return Hi, ${val}!
};
greet ('cool coders');
Juan Luna Ramirez
9,038 PointsJuan Luna Ramirez
9,038 PointsGood catch Jordan!