Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Array Iteration Methods Combining Array Methods Working with Objects

victor escarcega
victor escarcega
15,083 Points

Working with map

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

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

7,902 Points
// 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}`;
Steven Parker
Steven Parker
218,861 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}`);