"This" works for everyone


#1


Could anyone help me?!
It says ' Make sure to set susan's setAge property to be the setAge function. '


// 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;
bob.setAge = setAge;
  
// make susan here, and first give her an age of 25
var susan = new Object();
susan.age = 25;
susan.setAge = setAge;

// here, update Susan's age to 35 using the method
susan.setAge = function (newAge) {
    this.age = 35;
};
susan.setAge(35);


#2

// here, update Susan's age to 35 using the method
so you just have to do

susan.setAge(35);

you don't need

susan.setAge = function (newAge) {
    this.age = 35;
};

because there is already a method

var setAge = function (newAge) {
  this.age = newAge;
};

#4

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