17."this" works for everybody


#1

So, I just completed exercise 16, and finally understood a little bit about methods. Now, I move on to exercise 17, and it's basically the same thing but with a different name, but I keep getting it wrong and getting the same error "Oops, try again. Make sure to set susan's setAge property to be the setAge function". I even copied and pasted from exercise 16 and changed the name but I still keep getting the error, so I need some help.

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

var bob = new Object();
bob.age = 30;

bob.setAge = function (age) {
this.age = age;
};

bob.setAge(50);

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

var bob = new Object();
bob.age = 30;
bob.setAge = setAge;

var susan = new Object();
susan.age = 25;

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

susan.setAge(35);


#2

Follow the same code pattern used for bob.setAge.


#3

Thank you for the hint, thanks to that I solved it and found out another way to do it. But how come when I did the method for exercise 16 it worked but for 17 it didn't?


#4

Can't say for sure. It may be that the SCT allowed it in one lesson, and not the other.


#5

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