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

code challenge help

var contact = { fullName = function printFullName () }

I am reading MDN and W3C and still don't understand.

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

var contact = {
 print = function printFullName () {
}

4 Answers

David Axelrod
David Axelrod
36,073 Points

Hello Sharon! You're almost there! just move the code for the first function into the print property of the contact object literal!

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

David's answer is correct.

the challenge is asking that you create a method called fullName that runs the printFullName function. So your code should look like this. View Below

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

var contact = {
  fullName: printFullName
}

i hope this helps

David Axelrod
David Axelrod
36,073 Points

Hey Chyno! I thought the same thing too! problem is that it doesnt pass the second part of the code challenge :( I think they're really trying to cement the idea of anonymous functions

oh. ok I didn't go that far. I'll check it out right now and see how I can help if David's answer doesn't work.

thank you for your help.

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