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

JavaScript JavaScript Functions Arrow Functions Default Function Parameters

Anthony Manriquez
Anthony Manriquez
2,917 Points

Writing as an arrow function

I tried writing the same code as an arrow function one-line statement and mine keeps returning "undefined", I was wondering if anyone could point out what I'm doing wrong here.

const sayGreeting = (greeting = 'Good Morning' , name = 'student') => {${greeting} ${name}!};

2 Answers

Anthony Manriquez
Anthony Manriquez
2,917 Points

I played around with it more and removed the brackets from my template literal and was able to get it working!

Tony Idehen
Tony Idehen
8,060 Points

Try using const sayGreeting = (greeting = 'Good Morning' , name = 'student') => { return ${greeting} ${name}!; } sayGreeting();