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

Annika Noren
Annika Noren
26,930 Points

Trouble with "Call and Apply" Challenge Question

I must be close, but something is off. I've put in

greeting.apply(andrew,args1);

but it's not working. What am I overlooking or missing?

4 Answers

Hi Annika,

You code is actually correct but the challenge wants you to write the code like this:

var greeting = genericGreet.apply(andrew,args1);
John Grillo
John Grillo
30,241 Points

So does it want the .call method as opposed to the .apply method?

Annika Noren
Annika Noren
26,930 Points

Thank you!

Do you have an easy & short explanation as to why it needs to be like that? I'll rewatch the video, but if you have time to explain it that would be great!

I appreciate the help on the challenge.

Both answers are correct. You did nothing wrong. I tested your code in my browser and it works fine. For some reason the challenge only accepts that 1 answer.

I believe the problem with your answer is that you would be calling the undefined greeting variable and trying to apply the Andrew object and arguments to it, and the challenge is asking you to set the genericGreet method with the Andrew object and arguments applied to it as the greeting variable.

Maureen O'Neal
Maureen O'Neal
12,930 Points

Yes, I had the same problem, it's confusing what exactly is desired.

Avery Kachline
Avery Kachline
10,458 Points

Thank you both (John Grillo & Annika Noren)

I had the same solution as Annika with the

|| greeting.apply(andrew,args1); ||

Watch the video like 4 times and was not putting the pieces together. John code of

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

Worked like a charm!

John Grillo
John Grillo
30,241 Points

Avery Kachline, Glad to hear that || var greeting = genericGreet.apply(andrew,args1); ||

did the trick!