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

mehmet odabas
mehmet odabas
2,120 Points

string error

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

it says it is expecting return keyword... i didn't understand what it expects i wrote the return keyword inside of the function

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

2 Answers

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

  }
}

It says you have to change the console.log statement to return statement.

mehmet odabas
mehmet odabas
2,120 Points

i've tried it too i typed this code and didn't work. return this.firstName + this.lastName;

mehmet odabas
mehmet odabas
2,120 Points

and your code works. but why mine didn't?

Well maybe something went wrong when the data was sent to the checker. Nextime, to save you the nerves -> copy the code you have written -> refresh the page -> paste the code in and check again.