The "this" Keyword


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/spencer-sandbox/2/4?curriculum_id=506324b3a7dffd00020bf661#

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

```

// 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(50);

// change bob’s age to 50 here
bob.setAge(50);

<do not remove the three backticks above>

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

#2

// 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;
bob.setAge(50);
// change bob’s age to 50 here


#3

Seems you figured it out?


#4

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