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 Adding a Method to an Object

Tiffany White
Tiffany White
5,373 Points

Not sure what I am being asked to do here.

Not sure what they're asking here. Use the programming from printFullName. I cut the programming and add it to contact and add a fullName variable to the contact object literal but that doesn't work. Not sure what to do?

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

var contact = {
  var fullName 
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Tiffany,

Andrew wants a method created on the object contact in Task 1. So basically all the code that is the function will be moved into contact as a method called fullName like so...

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

If you want, you can review this starting at ~1:00 in this video.

Keep Coding! :dizzy: