Hello all,
I was able to finish this exercise using forEach, but I wanted to try .map too.
However, when I use the curly brackets in a certain spot, the code doesn’t work. Here’s the working code:
function shoutGreetings(arr) {
const newWords = arr.map(word =>
word.toUpperCase() + "!");
return newWords;
}
I wanted to put the curly bracket just after the fat arrow and after the quotation for the exclamation point. Like this:
function shoutGreetings(arr) {
const newWords = arr.map(word => {
word.toUpperCase() + "!"});
return newWords;
}
But when I do that, the function returns six “undefined” in an array.
The problem is, I’ve seen other .map functions that work just fine with these curly brackets. Why doesn’t it work here? And is there a rule for when to use/not use the curly brackets in .map like this?
For example, the .map introduction page includes two different examples:
const bigNumbers = numbers.map(number => {
return number * 10;});
and also
const secretMessage = animals.map(animal => animal[0]);
The first one uses curly brackets, the second one doesn’t.