26/30


#1

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

this.askTeller = function(pass) {
if (pass == 1234) return bankBalance;
else return "Wrong password.";
};
}
var john = new Person('John','Smith',30);
/* the variable myBalance should access askTeller()
with a password as an argument */

var myBalance = john.askTeller(1234);

Question: this program worked. But my question is: in creating var myBalance, why did I have to include john?
why would var myBalance = askTeller(1234) not have worked?


#2

You must include john because .askTeller requires an object to operate on.