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

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.