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 Returning Values

Micheal Emerson
Micheal Emerson
8,207 Points

Stuck on returning values challenge

Instead of logging out the full name, modify the code so it returns the string instead. Started with:

console.log(this.firstName + " " + this.lastName);

I changed it to the current code:

return "fullName";

Not sure what is wrong!

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

2 Answers

So for this you will need to return something using return You had the right idea with console.log() but instead of logging it, you need to return what you where going to log.

 console.log(this.firstName + " " + this.lastName);
Tommy Gebru
Tommy Gebru
30,164 Points

How can we call .log methods? Using the example below:

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