shoutGreetings() syntax question

Hi guys and gals, I’ve written a very basic bit of code that takes an array of strings and returns an array composed of each original string converted to caps and appended with an exclamation mark.

Input: [‘hello’, ‘hi’, ‘heya’, ‘oi’, ‘hey’, ‘yo’]

Expected output: [ ‘HELLO!’, ‘HI!’, ‘HEYA!’, ‘OI!’, ‘HEY!’, ‘YO!’ ].

Is anyone able to tell me why the first Codebyte returns the expected output but the the second and third ones return “SyntaxError: Unexpected token )” on line 5. MDN documentation seems to say that the third one is correct syntax but I’m obviously missing something. Thanks in advance!

const greetings = ['hello', 'hi', 'heya', 'oi', 'hey', 'yo']; const shoutGreetings = (arr) => { return arr.map(word => word.toUpperCase() + '!'); } console.log(shoutGreetings(greetings))
const greetings = ['hello', 'hi', 'heya', 'oi', 'hey', 'yo']; const shoutGreetings = (arr) => { return arr.map(word => { word.toUpperCase() + '!'); } } console.log(shoutGreetings(greetings))
const greetings = ['hello', 'hi', 'heya', 'oi', 'hey', 'yo']; const shoutGreetings = (arr) => { return arr.map((word) => { word.toUpperCase() + '!'); )}; } console.log(shoutGreetings(greetings))

Hi,
the third and the second have the same syntax error:

return arr.map(word => {

    word.toUpperCase() + '!');

  }

You need to close the brackets in the sandwich principle:

({})

And if you don’t use shorthand syntax, you need to use the return keyword.

1 Like

the error is at ’ word.toUpperCase() + ‘!’); ’ wrong closing tag

const greetings = ['hello', 'hi', 'heya', 'oi', 'hey', 'yo']; const shoutGreetings = (arr) => { return arr.map(word =>word.toUpperCase()+'!') } console.log(shoutGreetings(greetings))
1 Like