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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Austin Yeater](https://secure.gravatar.com/avatar/ed9b82e2c98af09b47a1e9ee12cdedc6?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Austin Yeater
5,510 Pointshow do you Convert the greet function declaration to an arrow function. HINT: Arrow functions are not hoisted – or lif
const greet('cool coders') => ;
function greet(val = 'Austin') {
return `Hi, ${val}!`;
}
1 Answer
![Jason Larson](https://uploads.teamtreehouse.com/production/profile-photos/11651180/micro_JLarson-Crop3.jpg)
Jason Larson
8,359 PointsYou were on the right track by making the arrow function at the top, but you were working on the wrong part. That first line is calling the function, and since you are converting the function to an arrow function, you leave that line as it is, but move it down below the function declaration. As for the arrow function itself, you are going to remove the 'function' keyword and replace it with let or const, then put an equal sign after the name, then stick the arrow between the parameters and the curly braces:
const greet = (val) => {
return `Hi, ${val}!`;
}
greet('cool coders');
Note that because this is just a single line of code in the function, and it's the return statement, you can shorten this by eliminating the curly braces and the return keyword. (If you have more than one line of code, you'll need to use the curly braces and remember to return
anything you need to get from your function.) You can also get rid of the parentheses around the parameter, though you'll need to have it if you want to use a default parameter like you are trying to do in your code:
const greet = val => `Hi, ${val}!`;
greet('cool coders');
const greet = (val = 'Austin') => `Hi, ${val}!`;
greet();