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 Returning Values

David Dehghani
David Dehghani
6,992 Points

Object basics in JS help.

I feel like I'm close to grasping the concept of objects but I can't figure out what seems to be an easy question.

object.js
var contact = {
  firstName: "Andrew",
  lastName: "Chalkley",
  fullName: function() { 
    this[firstName] + " " + this[lastName] 
                       };
    return fullName;
}

David, Hi. I see what you did and it looks like it should pass the challenge, but apparently not. I posted what passed for me. It's almost identical to yours

I just noticed you have the return for the fullName method outside that function. Maybe it will pass if you make that small change

fullName: function() { 
    this[firstName] + " " + this[lastName] 
    return fullName;
};

:D

1 Answer

var contact = {
  firstName: "Andrew",
  lastName: "Chalkley",
  fullName: function(){
    return this.firstName + " " + this.lastName;
  }
}
David Dehghani
David Dehghani
6,992 Points

I was so close. The syntax is JS is so tight, I'm always feeling like I'll miss something small. Thanks for the help!