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 trialChris Thomas
Front End Web Development Techdegree Graduate 34,909 PointsJavaScript array returning undefined.
I'm having a bit of trouble with this code challenge. It keeps returning undefined. I'm using ES6 arrow syntax. I've attached my code to the question.
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 should be: ["Beatrix Potter", "Ann Martin", "Beverly Cleary", "Roald Dahl", "Lewis Carroll"]
// Write your code below
fullAuthorNames = authors.map(name => `${authors.firstName} ${authors.lastName}`);
2 Answers
Steven Parker
231,236 PointsIn your template string, you need to format using the properties of each item ("name") . The collection itself ("authors") doesn't have those properties.
Chris Thomas
Front End Web Development Techdegree Graduate 34,909 PointsAhh got it! Thank you!
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 should be: ["Beatrix Potter", "Ann Martin", "Beverly Cleary", "Roald Dahl", "Lewis Carroll"]
// Write your code below
fullAuthorNames = authors.map(name => `${name.firstName} ${name.lastName}`);
``