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

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.