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 Call and Apply

Undefined Object?

I am not sure why my var greeting = andrew.genericGreet.apply(andrew, args1) is returning an undefinded object...

3 Answers

The andrew object has no genericGreet method/property, and you are trying to get to it and use the apply method on it.

Instead, you should be doing this on the genericGreet function, and pass andrew as a parameter:

var greeting = genericGreet.apply(andrew, args1);

After watching the video again, I moved the genericGreet object inside the andrew object and used

var greeting = andrew.genericGreet.apply(andrew, args1);

This works too. Thanks!

I took a print shot of the code and wanted to show people by posting it here but I don't know how to post codes in the forum like you so that people can cut and paste it to try. How do you do it?

And how do I test the treehouse codes on console like the videos??

That might work, but it wasn't really the point of the code challenge — your solution is more complicated than it should be.

You can read about posting code here, or check the Markdown Cheatsheet under the post text field.

Oh and you can find how to open the JavaScript console in various browsers here. Then you can just enter the code into the console and test it out.