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

add this to the method with property values.

At first onset the question appears to be relatively easy, however the implementation I found was a cascade of property nesting within the method declaration. As a way to circumvent "this", I used property values of first and last name above the method so as to maintain stack call ordering. The question I keep having is there another way to do this. And I also have a syntax error, can you find it?

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

The code above is incorrect, could someone point me in the right direction.

2 Answers

Steven Parker
Steven Parker
231,275 Points

:point_right: Your object properties should be separated with commas, not semicolons.

Then, the contents of the function should look something like this:

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

still did not work