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 trialAngelica Islas
4,082 PointsHow do I solve this challenge?
greet('cool coders');
function greet(val) {
return `Hi, ${val}!`;
}
3 Answers
Denis Omerovic
2,377 PointsYou must declare function first, otherwise, it won't work.
const greet = (val) => {
return Hi, ${val}!
;
}
greet('cool coders');
Martin Ulč
15,396 PointsExactly as Denis mentioned. If you create a function declaration then it does not matter if you call the function before or after initialization. It will work. However, in case of an arrow function or a function expression the function initialization has to be before the call otherwise the console throws an error and it won't work.
Angelica Islas
4,082 PointsI tried to run this in JS console and got the following message. What is this wrong?
const greet= (val)=> {return Hi, ${val}!;}
greet('cool coders'); VM34:1 Uncaught SyntaxError: Unexpected token '{'
Martin Ulč
15,396 PointsHi, you apparently omitted the quotation marks. Try this:
const greet = (val) => {
return `Hi, ${val}!`;
}
greet('cool coders');
Denis Omerovic
2,377 PointsYou are probably missing backticks ``
const greet = (val) => {
return `Hi, ${val}!`;
}
greet('cool coders');