16. The "this" Keyword


#1


A method to Madness
Lesson/No. 16


The output of my code return 'undefined' but the system take the answer as correct. I don't know if this is correct or what.

This is my code on Lesson 16
// 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 = setAge;

// change bob's age to 50 here
console.log(bob.setAge(50));


Replace this line with your code.


#2

after reading from forums i found the answer.

bob.setAge(50);
console.log(bob.age);


#3

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