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 1 of 1 Convert the greet function declaration to an arrow function.

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

greet('cool coders');

Answer is in the code.

Tom Nguyen
Tom Nguyen
33,500 Points

This is the solution. works for me.

lance rangel
lance rangel
2,016 Points

The issue is due to the semicolon after the return statement. It should go at the end of the functions closing bracket as such:

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

A couple of other ways to do this in one line would be:

const greet = val => `Hi, ${val}!`;  
//or  
const greet = (val = 'cool coders') => `Hi, ${val}!`;

I hope this helps!

Steven Parker
Steven Parker
231,184 Points

Actually, it's correct (and "best practice") to put a semicolon after the assignment and after the return statement.

But they are both optional, neither one is necessary for the code to function correctly.

6 Answers

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

greet('cool coders');
Steven Parker
Steven Parker
231,184 Points

Are you suggesting something to change? I can't see any difference from the original code here.

Steven Parker
Steven Parker
231,184 Points

What kind of error do you get? This looks OK, and when I paste it directly into the challenge, it passes!

You might try restarting your browser.

Lateefah Camacho
Lateefah Camacho
3,067 Points

const greet =(val) => { greet('cool coders'); return Hi, ${val}!; }; copy and paste reformatted post.

That was very odd. It doesn't work in a browser but if you paste the code above into the challenge it passes.

can someone please help me I'm so lost i hate JavaScript :(

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

greet('cool coders'); this works