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 trialvictor E
19,146 PointsWorking 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
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 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}`;
});
victor E
19,146 Pointsvictor E
19,146 PointsSuper helpful thank you Senpai!
Steven Parker
231,248 PointsSteven Parker
231,248 PointsThis would also be a good place to use the compact form of an arrow function:
fullAuthorNames = authors.map(i => `${i.firstName} ${i.lastName}`);