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

Convert the greet function declaration to an arrow function. HINT: Arrow functions are not hoisted – or lifted – to the

script.js
greet('cool coders');

function greet(val) {
  return `Hi, ${val}!`;
}

1 Answer

Heidi Fryzell
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 Points

Hi Nathalie,

For the challenge you have to convert the function to an arrow function and assign it to a variable, as arrow functions can't be standalone functions. And then you have to move where you calling the function below where you assign the function to a variable because you can't call it before it exists as a variable.

So here is my code that will pass the challenge.

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

greet('cool coders');

If this does not make sense, I would recommend re-watching the 3 videos that come before the challenge.

Happy coding!

Heidi Fryzell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 Points

And you actually can write the arrow function even more concisely. This will also work:

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

greet('cool coders');