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

Paul O'Sullivan
Paul O'Sullivan
1,514 Points

can't figure this out

Modify this object so it uses two properties firstName and lastName and remove their variable declarations from the fullName method. Don't do anything to the console.log() call right now.

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

3 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi Paul, the code challenge requires for you to change the variables firstName and lastName into properties and to remove them from the fullName method, this can be done in the following way:

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

Note the syntax of each property and how it differs from the variable syntax, also remember to place a comma after each property/method except for the last one :)

hope this helps!!

Zoltán Holik
Zoltán Holik
3,401 Points
var contact = {
  firstName: "Andrew",
  lastName: "Chalkley",
  fullName: function() {
    console.log(this.firstName + " " + this.lastName);
  }
}
Paul O'Sullivan
Paul O'Sullivan
1,514 Points

thanks Guys. I had a silly mistake i forgot to change = to : when I changed the variables to properties