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 trialEndless OS Team
Courses Plus Student 1,335 PointsI'm constructing an object with properties and a console.log() call. Why isn't it recognizing my property values?
This is my object:
var contact = { firstName: "Andrew", lastName: "Chalkley", fullName: console.log(contact.firstName + " " + contact.lastName) }
It's telling me that it's contact.firstName and contact.lastName are undefined, not objects ...
I also tried this.firstName and this.lastName, still didn't work. Help :(
var contact = {
firstName: "Andrew",
lastName: "Chalkley",
fullName: console.log(this.firstName + " " + this.lastName)
}
1 Answer
Umesh Ravji
42,386 Points fullName: function() {
console.log(this.firstName + " " + this.lastName)
}
Is what you are looking for, you have removed the function for some reason :)
Endless OS Team
Courses Plus Student 1,335 PointsThank you! I thought I did try that -- was probably getting frustrated and stopped, haha. Thanks a bunch!
Edward Ries
7,388 PointsEdward Ries
7,388 Pointsconsole.log doesn't belong inside of your object. I'm taking a small guess here as I haven't tested it but "this" is typically used to access properties on within a function. I'm not sure if you can directly access the values your setting while creating the object but just in case, try fullName: contact.firstName + ' ' + contact.lastName; See if that helps.