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

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

Please give me answer of this code

What have you tried so far?

Posting code in the forum

5 Answers

All you have to do is add a property (method in this case) called greet to both objects and point it to the genericGreet function. Something like this:

function genericMethod () {
   // do something
}

var myObject = {
   someProperty: "something",
   myMethod: genericMethod   // We use the genericMethod function as a property of this object
}

interested in this also, stuck!

Why don't you post what you've attempted so far as Jason Anello suggested?

I'm having some trouble to do this Challenge too. I was trying by calling the function and using "apply" on it, like this:

greeting.apply(andrew, args1);

But is not working. How can we deal with it?

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

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

      var ryan = {
        name: "Ryan",
        greet: genericGreet
      };
      andrew.greet();
            ryan.greet();

I believe if you leave out "andrew.greet();" and "ryan.greet();"... your code should be fine. I don't think the task is asking for an output.