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

Objects - exercise on Understanding this

Not clear challenge task. It says - "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." - I have few questions:

  • do we need to delete the fullName property?
  • how can we add two more prperties (firstName and lastName) without values? I tried just to add firstName and lastName and just remove variables from fullName property and it didn't work.
object.js
var contact = {
  firstName: function() {
    console.log(firstName + " " + lastName);
  },
  firstName: ,
  lastName: 
}

3 Answers

Vladut Astalos
Vladut Astalos
11,246 Points

No you don't delete the fullName property you delete only variable declarations in that property and make them properties on their own.

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

do we need to delete the fullName property?

No, you do not.

how can we add two more prperties (firstName and lastName) without values?

You aren't meant to add them without values. You are meant to use the same values as they were assigned when they were placed in the fullName method. In other words firstName should equal "Andrew", and lastName should equal "Chalkley".

Thank you, Andren & Vladut!