Why code is not succsefully run directly using...console.log(john.bankBalance);...............without saving it in myBalance


#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(john.getBalance());


#2

You might need to create a variable of myBalance so that it does that then you could console.log()

var myBalance =  john.getBalance(1234);

Hope I helped! :slight_smile:


#3

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