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 trialKevin Tucker
4,987 PointsArrow Functions
I've gone through videos but I still can't solve this challenge, could someone shed some light? Its driving me nuts.
greet('cool coders');
function greet(val) {
return `Hi, ${val}!`;
}
4 Answers
Dimitar Dimitrov
11,800 PointsFirst you need to declare the function expression and then call it because arrow functions are not hoisted on the top of the code
let greet = (val) => {
return `Hi, ${val}!`;
}
greet('cool coders');
Dimitar Dimitrov
11,800 PointsThe greet("cool coders") code is where the function is called with string argument "cool coders"
seth aruby
10,111 PointsDimitar's solution is a perfectly fine one. You could even simplify it further with the following:
const greet = x => `Hi, x`;
greet('cool coders');
Thus utilizing the implicit return w/o curly braces concise syntax. https://teamtreehouse.com/library/javascript-functions/arrow-functions/concise-arrow-function-syntax
David Wollett
2,194 PointsArrow expressions are not my strong suit for sure. One of my mistakes ('for the past hour') was writing a whole separate code along with the code already given to me. Of course kept getting the 'Greet function has already been defined' error. This community helped me straighten that mistake out. Thanks guys!
Kevin Tucker
4,987 PointsKevin Tucker
4,987 PointsThank you for that. What does this section of code do: greet('cool coders');. I kept trying to include in the arrow function which is where I was going wrong.