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 Array Iteration Methods Combining Array Methods Working with Objects

victor E
victor E
19,146 Points

Working with map

not sure what I am missing, the error says I am missing ) after argument,

app.js
const authors = [
  { firstName: "Beatrix", lastName: "Potter" },
  { firstName: "Ann", lastName: "Martin" },
  { firstName: "Beverly", lastName: "Cleary" },
  { firstName: "Roald", lastName: "Dahl" },
  { firstName: "Lewis", lastName: "Carroll" }
];
let fullAuthorNames;
fullAuthorNames = authors.map(i => {
  i = `${authors.firstName}, ${authors.lastName}`;
  return i;
};)



// fullAuthorNames should be: ["Beatrix Potter", "Ann Martin", "Beverly Cleary", "Roald Dahl", "Lewis Carroll"]
// Write your code below

1 Answer

// Pretty close, but there are a 3 issues with your code
// You can't use authors to get firstName and lastName, because authors returns the whole key value array
// and now the individual block
i = `${authors.firstName}, ${authors.lastName}`;

// If you look at your code here, you can use the ' i ' to retrieve the individual block
// which would look like this: { firstName: "Beatrix", lastName: "Potter" },
// now with this block you can use .firstName and .lastName
fullAuthorNames = authors.map(i => {

// Code corrected
// You don't need the ' ,  ' here
${i.firstName}, ${i.lastName}

// move ' ) ' before ' ; '
};)
// like this
});

// Also you don't need to use i =  `${i.firstName}, ${i.lastName}`
// you can just
return `${i.firstName} ${i.lastName}`

// Final look
fullAuthorNames = authors.map(i=> {
  return `${i.firstName} ${i.lastName}`;
});
victor E
victor E
19,146 Points

Super helpful thank you Senpai!

Steven Parker
Steven Parker
231,275 Points

This would also be a good place to use the compact form of an arrow function:

fullAuthorNames = authors.map(i => `${i.firstName} ${i.lastName}`);