Need help Oops, try again. Make sure you properly defined the askTeller method!


#1

function Person(first,last,age) {
   this.firstname = first;
   this.lastname = last;
   this.age = age;
   var bankBalance = 7500;
}
  
   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

First of all according to the {} askTeller is not inside of the object so the this. doesn't make any sense. At least it is not connected to the Person constructor (did you hear about prototype yet?). Also you need to define that returnBalance ... I guess it is a method anywhere. What exercise is this about?


#3

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

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


#4

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

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


#5

this??
is what you mean?????


#6

better at least now askTeller is part of the function. Now you should have a look at what returnBalance actually is, afaik it is a private method of Person that is passed via askTeller. But in your code it doesn't exist yet.