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

Javascript Foundations > Objects > Methods Code Challenge

I"m really pretty lost with what this code challenge is asking.

On 'andrew' and 'ryan', set the 'greet' method as the 'genericGreet' function.

var genericGreet = function() {
        return "Hello, my name is " + this.name;
      }

      var andrew = {
        name: "Andrew"
      }

      var ryan = {
        name: "Ryan"
      }

The stuff I put in just came back "Bummer! Null".

3 Answers

Just take out the parenthesis after the function call.

Nice. Thanks, this helped. Stupid commas!

Just like name, you should have greet. And just like the strings you should have the function. I hope that wasn't to cryptic for you.

What is wrong here.

 var genericGreet = function() {
    return "Hello, my name is " + this.name;
  }

  var andrew = {
    name: "Andrew";  
    greet: genericGreet();

  }

  var ryan = {
    name: "Ryan"
    greet: genericGreet();

G S,

In andrew and ryan, you want a reference to the genericGreet function. But when you put the parenthesis after the function name, genericGreet(), then you actually immediately execute the function instead of saving a reference to the function in the object. Removing the parens should solve the issue.

Thanks Chris, that worked. I think it was also because I didn't put a comma after 'name: "ryan"' and 'name:"Andrew"', and also I didn't need semi-colons.

      var andrew = {
    name: "Andrew",
    greet: genericGreet
  }

  var ryan = {
    name: "Ryan",
    greet: genericGreet
  }