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

Brian Schmitz
Brian Schmitz
11,167 Points

Setting the "Greeting" Variable challenge

Can someone please take a look at my code here and let me know where I am missing in trying to set up the Greeting variable. Much appreciated. Thanks

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"
    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 args1 = ["Michael", "awesome", ":)"];

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

1 Answer

Your variable "greeting" is wrong. Simply remove the ".greet" :)

var greeting = genericGreet.apply(andrew, args1);
Brian Schmitz
Brian Schmitz
11,167 Points

Thanks Bryan. How about this last challenge in the prototypes section where they want us to set the prototype's wheels to 4. Here is my code:

  wheels = new Car (4);

Like so:

function Car(model) {
    this.model = model;
        Car.prototype = carPrototype;
        Car.prototype.wheels = 4;
      }

After setting "Car.prototype" to equal the object "carPrototype", the last line creates a new key of "wheels" and gives it the value of 4, inserting it into the object.

This is probably the most confusing part of JavaScript to get a grip on, so do some Googling and rewatch the videos :)