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

JavaScript Code Challenge Help Needed

Set the 'greeting' variable, on line 29, by using the 'genericGreet' function in the context of 'andrew' with the array of arguments, 'args1'.

<!DOCTYPE html> <html lang="en"> <head> <title> JavaScript Foundations: Objects</title> <style> html { background: #FAFAFA; font-family: sans-serif; } </style> </head> <body> <h1>JavaScript Foundations</h1> <h2>Objects: Call and Apply</h2> <script> var genericGreet = function(name, mood) { name = name || "you"; mood = mood || "good"; return "Hello " + name + ", my name is " + this.name + " and I am in a " + mood + " mood!"; }

  var andrew = {
    name: "Andrew"
  }

  var args1 = ["Michael", "awesome", ":)"];

  var greeting = genericGreet.call (args1);
</script>

</body> </html>

2 Answers

You are pretty close, but you are using the wrong method from the previous lesson. You are using the .call() method, but the quiz is looking for the .apply() method. I don't want to give you the full answer, but watching the video again, primarily starting around minute 9:00 should lead you right to it.

Riley

Thanks for the clue I will go back and watch the video again

Irfan Ullah
Irfan Ullah
6,869 Points

you need

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