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

Wesley Haines
Wesley Haines
4,934 Points

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

Cannot seem to figure out what is wrong here...

<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 (andrew, ["Michael", "awesome", ":)"]);
</script>

2 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Wesley,

Without knowing exactly what you want the final sentence to say, I've done my best to create a sentence that makes sense using the base of the code you have provided.

To get the value "Andrew" in your function you need to get it with the property "name" as it is set on the object named "andrew". Since you are passing an array to your function, you need to get the value you want by index. I've done this to get the mood of "awesome" to use in the sentence. You'll notice I use the same technique to acquire the values form the "mood" array to fill the sentence.

Please let me know if I can help to get the exact sentence you are looking for. Hope this helps.

<script>
  var genericGreet = function(name, mood) {
          return "Hello " + name.name + ", my name is " + mood[0] +
                 " and I am in a " + mood[1] + " mood! " + mood[2];
   }

   var andrew = {
         name: "Andrew"
   }

   var args1 = ["Michael", "awesome", ":)"];
   var greeting = genericGreet (andrew, args1);
</script>

you have to use the apply method that allow you to pass agrs1 in the context of andrew.

  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.apply(andrew, args1);