Hi everyone. I’m doing the code challenge shoutGreetings, but I have a doubt about the multi-line function.
I wrote my code, and compared to the answer it doesn’t look wrong. However, when it’s put in a single line it works fine. Why it isn’t working as it is? I can’t figure it out.
const shoutGreetings = arr => {
arr.map(word => {
return word.toUpperCase() + ‘!’
})
};
the console logged Undefined.
https://www.codecademy.com/journeys/back-end-engineer/paths/becj-22-software-engineering-foundations/tracks/becj-22-javascript-syntax-part-ii/modules/wdcp-22-practice-javascript-syntax-arrays-loops-objects-iterators-d60aa91e-2acc-4f5c-945f-917ae314b322/lessons/intermediate-javascript-coding-challenge/exercises/shout-greetings
shoutGreetings
does not return anything.
Either you write
const shoutGreetings = arr => arr.map(word => {
return word.toUpperCase() + ‘!’
});
(no curly braces around the outer function implies return)
or you write
const shoutGreetings = arr => {
return arr.map(word => {
return word.toUpperCase() + ‘!’
})
};
Thanks for the help. Thanks also for the link on how to properly format the code. I didn’t know.
1 Like