Accesing Private Variables | Make sure john has a properly defined function getBalance


#1

I don’t understand why this would not work, It seems to be flawlessly working for me but it keeps error with

BlockquoteOops, try again. Make sure john has a properly defined function getBalance

function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
}
   this.getBalance = function() {
      // your code should return the bankBalance
      return bankBalance;
};

var john = new Person('John','Smith',30);
console.log(john.bankBalance);

// create a new variable myBalance that calls getBalance()
var myBalance= john.getBalance();
console.log(myBalance);


sorry I’m not a paid memeber…


#2

The getBalance method should be inside of Person constructor


#3

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