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 trialKhatia Bagaturia
2,050 PointsHi Guys ! I am trying to convert Greet Function to Arrow Function . Looks like I ' am doing alright but it does notwor
function greet = (val) => {
return `Hi, ${val}!`;
}
greet ('cool coders');
1 Answer
Helari Sosi
6,168 PointsHi Khatia, you are almost right but instead of declaring a function greet
you need to declare it as a variable. Little bit extra read for you on arrow functions - Arrow Functions, the basics
The whole point of the arrow function is to make your code shorter and better to read.
- In your case, it needs to be declared as a variable not a function
- When it only has one argument, there is no need for parenthesis "()". Same if the code execution is only one line of code - in your case
Hi, ${val}!
, there is no need for the curly brackets to wrap the code. - Also with arrow functions when it is as simple as that you don't need the "return" inside the function. It does it automatically for you.
//Arrow function
const example = value => `Hi, ${value!}`;
//Same code with function declaration
function example(value){
return `Hi, ${value}!`;
}
Hope it helps, let me know if you have any more questions!