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 trialRicky Redman
7,520 Pointsarrow function
I'm ot understanding how to create the arrow function for this challenge
greet('cool coders');
function greet = () => (val) {
return `Hi, ${val}!`;
}
1 Answer
Manil Boudjemai
8,574 PointsHi Ricky,
First, declare a variable named after the function (my personal preference is to store functions inside variables). The variable, in this case, contains the function (block of code designed to perform a particular task).
Then, set greet to the function. The function can list parameters, if you wish. You can leave out the parenthesis if your function has a single parameter. Parameters are arguments to be imported into the function, when called.
Finally, type the => followed by curly braces; within goes the function's content:
var greet = val => {
return `Hi, ${val}!`;
}
Test by printing to the console.
Call the function by the variable's name.
Replace val
by the argument you want to pass into the function.
console.log( greet(`Ricky`) );