26. Passing Arguments


#1

I can not figure this one out.

TypeError: Person.askTeller is not a function
Oops, try again. Make sure to set myBalance equal to calling john's askTeller method with 1234 as the argument

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 = Person.askTeller();
console.log(myBalance)

#2

I got it, after trying a bunch of different things.

 var john = new Person('John','Smith',30);
    /* the variable myBalance should access askTeller()
       with a password as an argument  */
    var myBalance = john.askTeller(1234);

I realized i had to switch my mistake

 ... = person.askTeller(1234);

and actually put in the person john

... = john.askTeller(1234);


#3

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