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

Challenge task help

I don't understand what's wrong what should i do to fix this?

script.js
greet('cool coders');

const greet = (val) => {
  return `Hi, ${val}!`;
}

2 Answers

Cameron Childres
Cameron Childres
11,820 Points

Hi Haki,

Your arrow function is looking good. Note that you call the function, and then you define it. Pay attention to the hint on this challenge:

HINT: Arrow functions are not hoisted – or lifted – to the top of their scope. Calling an arrow function before it's defined produces an error

Thank you but i still don't understand how would i define it, I just started doing this not too long ago so i'm not that good at it. How would i define the function when i call it?

Cameron Childres
Cameron Childres
11,820 Points

This is where you've called the function:

greet('cool coders');

This is where you've defined it:

const greet = (val) => {
  return `Hi, ${val}!`;
}

They're simply out of order. Move your call to the bottom, below the definition.

I got it now thank you for the help!

You've already defined the function, the only difference is that you are using an arrow function which means that it must be defined before calling it:

you called

greet('cool coders');

before your arrow function. Try switching them around! It should work.

Thanks for the help!