25/30 - Private methods


#1

Please any hint what am I doing wrong? When I try to run it, I get the message: "TypeError: Object doesn't support property or method" :imp:

My code:

function Person(first,last,age) {
this.firstname = first;
this.lastname = last;
this.age = age;
var bankBalance = 7500;
}

var returnBalance = function() {
return bankBalance;
};

// create the new function here
this.askTeller = function() {
return returnBalance;
};

var john = new Person('John','Smith',30);
console.log(john.returnBalance);
var myBalanceMethod = john.askTeller();
var myBalance = myBalanceMethod();
console.log(myBalance);


#2

With

function Person(first,last,age) {
    this.firstname = first;
    this.lastname = last;
    this.age = age;
    var bankBalance = 7500;
}

you have allready closed your Person object class constructor
and all of the other command lines are NOT included in this constructor

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

     var returnBalance = function() {
          return bankBalance;
     };

     // create the new function here
     this.askTeller = function() {
           return returnBalance;
     };
  };

#3

Fab, now I works! Thank you! :relaxed: