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

Challenge Task 1(andrew, greet, args1)


What is wrong with this code? I am following instructions and my output is the intended output.

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

      var andrew = {
        name: "Andrew"


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

    console.log( greet.apply(andrew, args1));

2 Answers

You are doing things in the code beyond the scope of the task. You have changed the name of the variable (greeting) that is supposed to hold the result of applying genericGreet to andrew.

There is no need for you to console.log anything. Of course, you can use it while practicing, but the code challenge will check the content of a variable once the challenge is run.

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

The only change you have to do is on line 29, and you just have to expand the code there (without modifying it).

Use the apply method on genericGreet on that line and pass the same parameters that you've used and you will pass the code challenge.

Thanks Dino!! your explanations are so clear:)