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

Jack Duong
Jack Duong
6,324 Points

Having trouble calling function in console. What did I do wrong?

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

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

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

I've tried ryan.greet() which gives me "object is not a function"; ryan.greet gives me "Object {greet: function}"

I'm unable to get the return value for the function

Jack Duong
Jack Duong
6,324 Points

This is the link to the challenge btw http://teamtreehouse.com/library/methods-3

  • which I passed.

1 Answer

Hi Jack,

The code that you have posted does not pass the challenge for me.

You have correctly set the greet method to the genericGreet variable but you should not have modified that variable at the top.

It was set to a function and you have changed it to an object. genericGreet is no longer a function now but an object.

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

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

      var ryan = {
        name: "Ryan",
        greet: genericGreet
      }
Jack Duong
Jack Duong
6,324 Points

Thanks! Can't believe I missed that. I really have to work on my attention to detail.