17. "This" Works for Everyone


#1

// 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
var setAge= function (newAge) {
this.age = newAge;
};
susan.setAge(35)

Here is my code i keep getting the Error message "Oops, try again. Make sure to set susan's setAge property to be the setAge function"

Please Help


#2

The only things I see immediately wrong is that you've missed out a couple of semi-colons (after susan.age=25 and susan.setAge(35)). You also don't need to write out the setAge function again, as it's already defined at the top of the code.

Fix those and see if it passes this time, but let me know if it doesn't.


#3

I figured out that You have to declare the variable and function before you declare Susan and you have to put in the semicolon after both susan.age=25 and susan.setAge(35))