"this"


#1


https://www.codecademy.com/courses/spencer-sandbox/2/4?curriculum_id=506324b3a7dffd00020bf661


I don't understand why it isn't working.

Oops, try again. It looks like you have an error in your code. Here's the message: ReferenceError: newAge is not defined


// here we define our method using "this", before we even introduce bob
var setAge = function (newAge) {
  this.age = newAge;
};
// now we make bob
var bob = new Object();
bob.age = 30;
// and down here we just use the method we already made
bob.setAge = newAge;
  
// change bob's age to 50 here
bob.setAge(50);


#2

why do you have this line:

bob.setAge = newAge;

it overwrites your setAge method with a undefined variable, why would you do that?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.