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 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.

Thanks!