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 trial

JavaScript JavaScript Functions Arrow Functions Create an Arrow Function

hello im confused it says make sure im calling the greet function. am i calling it correctly?

script.js
function greet = (val) => {
  return `Hi, ${val}!`
};
greet = 'cool coders';

2 Answers

I 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
Juan Luna Ramirez
9,038 Points

You 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');

thank 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');