24/30 - why cant I use this



Why can I not write this.bankBalance in the getBalance function instead of bankBalance? Is it because it is a local variable and not an attribute? Intuitively I thought this would work.

function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
   this.getBalance = function() {
      return bankBalance;
      //return this.bankBalance;
   this.getAge = function() {
    return this.age;

var john = new Person('John','Smith',30);

var myBalance = john.getBalance(); 
var myAge = john.getAge();


Is it because it is a local variable and not an attribute?


You are making things way too complicated for yourself in here. You only need to get the bankBalance not the age so you have extra lines of code in there. Also you never set john.getBalance(); so the code doesn't know where you got it for var myBalance. Also, you can not use this.bankBalance because it is a private attribute. It is set to where you have to call it by name instead of just adding it as a modifier.