Javascript. The "this" keyword


#1


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


Need help!
I don't understand why this message appears:

TypeError: bob.setAge is not a 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;
// and down here we just use the method we already made
bob.setAge = setAge();
  
// change bob's age to 50 here
bob.setAge(50);


#2

So for some reason you have added parenthesis to bob.setAge = setAge();

All you have to do is take out the parenthesis (). And your good as gold :slight_smile:

If that solved it please mark my answer as the solution, thanks.


#3

actually, it has already been there)
i solved it a few minutes earlier. but still i can't get some stuff of this

thanks, anyway!)


#4

Ah okay, no worries :slight_smile:


#5

YesJava101


#6

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