Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Foundations Objects Methods

Tong Vang
Tong Vang
9,926 Points

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

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

What am I doing wrong? These functions are killing me....

7 Answers

Tong, I strongly suggest copying and pasting your code. You'll save time and increase accuracy. Also:

If you look to the bottom right of the text box you will see something that says Markdown Cheetsheet. If you don't understand that maybe this will make sense: How to display code at Treehouse

<script>


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

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

    </script>

Hi Tong,

What happened to return "Hello, my name is " + this.name; in the function?

Jeff

Tong Vang
Tong Vang
9,926 Points

Its still there. I just left it out because it takes too long to type. Its still part of the genericGreet.

Tong Vang
Tong Vang
9,926 Points

Its still there. I just left it out because it takes too long to type. Its still part of the genericGreet.

From what I can see, the only error I spot is a typo after both greet methods. The semi-colons should be after the right curly brace. Also, you should have semi-colon at the end of the genericGreet function. Here's how it should look:

var genericGreet = function() {
    alert("Im working");
};

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

var ryan = {
    name: "Ryan",
    greet: andrew.greet
};
Tong Vang
Tong Vang
9,926 Points

Thanks Julian. I was thinking in term of function not object. Those semi colons caused the problem. It works now. Thanks again.

Tong Vang
Tong Vang
9,926 Points

Thanks Jeff. I'll do that next time.