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 Object-Oriented JavaScript (2015) Introduction to Methods Understanding this

Error message: The `contact.firstName` should be a string and so should `contact.lastName

Am I supposed to have [brackets] around a part of my code? What am I doing wrong?

object.js
var contact = {
  fullName: function() {
    contact.firstName = "Andrew";
    contact.lastName = "Chalkley";
    console.log(firstName + " " + lastName);
  }
}

1 Answer

You are close, you just need to use contact.firstName and contact.lastName. This is referring to your console.log statement. Unless declared elsewhere, variables "firstName" and "lastName" are never decalred. Hope this helps!

Oh, I remember now =) I just went back and redid the challenge. So you're defining an object here, both it's properties and it's methods. You want to do properties first so define what the first name is, define what the second name is, then create a function to create a full name.

var obj = {

    property1 : "thing",
    propterty2 : "another thing",

    function1: function()
    {
        console.log("This object has " + property1 + "and " + property2);
    }
}

Basically, define it's properties first, then create functions to manupulate those properties. Sorry for the vague first answer, it took going back to the challenge to remember what it was asking you to do.

Jeff Wilton
Jeff Wilton
16,646 Points

Good catch, James. I was just getting ready to respond with a similar post to your second one, but you beat me to it. :)