24. accessing private variables


#1

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);

Following error comes:

Oops, try again.
Remember to still print john.bankBalance!


#2

nevermind,,
line 14 was commented, "undefined" needed to be printed too


#3

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