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

Modify this object so it uses two properties firstName and lastName and remove their variable declarations from the full

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 = {
  firstName: "Andrew",
  lastName: "Chalkey"
    Console.log(firstName +" "+lastName);
}

4 Answers

Mariana Hoffmann
PLUS
Mariana Hoffmann
Courses Plus Student 11,046 Points

got it!

here's the code

part I

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

part II

var contact = {
  firstName: "Andrew",
  lastName: "Chalkey",
  fullName: function() {
    console.log(this.firstName + " " + this.lastName);
}
}
Damian Hutter
Damian Hutter
16,742 Points

hey,

If you want to log these names into the console you have to call them on their variable first. Right now you try to call two variables with the name 'firstName' and 'lastName', but there are no such variables. try to call the object variable first 'contact' followed by the dataname 'firstName'

e.g contact.firstName

Mariana Hoffmann
Mariana Hoffmann
Courses Plus Student 11,046 Points

hello, i'm stuck on the same challenge. i've already tried what you said up ahead, but it gets a parse error

here's the code:

var contact = {
  fullName: {
    contact.firstName = "Andrew";
    contact.lastName = "Chalkley";
    console.log(firstName + " " + lastName);
  }
}
Damian Hutter
Damian Hutter
16,742 Points

should be, because you need to call the data in this way, not assign it this way. So it should be like:

var contact = { firstName: "Andrew", lastName: "Chalkey" Console.log(contact.firstName +" "+ contact.lastName); }

hope this helps you out

Damian Hutter
Damian Hutter
16,742 Points

true, haven't missed the .this in the description. Nice job