26 and 24 have an unnecessary step


#1

Why do we declare a variable to run a method and not just run the method?

Exercise 24

Exercise 26


#2

@tonyhuang19,

The problem at hand.
with:

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.";
 };
 }

you have created a Person Class-constructor.
Look at this Person-Class-constructor
as if it is a template to create new object's
which are then called an Instance of the Person-Class.
var john = new Person('John','Smith',30);
console.log(john);
output =>
{ firstname: 'John', lastname: 'Smith', age: 30, askTeller: [Function] }

If you have a close look at the output, it is clear
that you have created an Instance john
with 4 publicly accessible properties,
firstName property with property-key firstName and it's associated string VALUE "John"
lastName property with property-key lastName and it's associated string VALUE "Smith"
age property with property-key age and it's associated number VALUE 30
askTeller property with property-key askTeller and it's associated function defintion VALUE ..function(pass) { function-body };
you will NOT see the bankBalance property
with a property-key bankBalance and it's associated number VALUE 7500

This is caused by the fact, that you were using the var-keyword,
in your template definition in the Person Class-constructor,
leading to this property being a private property to this object,
and NOT publicly visible as you have seen using the
console.log-Method

You can NOT access this private bankBalance property directly.

To access it you need to add a so-called getter Method,
So we have defined a this.askTeller property
which will be publicly accessible, and consists of
a property-key askTeller and it's associated function VALUE

this.askTeller = function(pass) {
 if (pass == 1234) return bankBalance;
 else return "Wrong password.";
 };

We create an askTeller function which takes 1 parameter pass.
This parameter-name is used throughout the function-body as
a variable.
In the if condition we do
the comparison of =local= variable pass being equal to number 1234
if the condition results into true then we return the bankBalance number Value
if the condition results into false then we return a string Value "Wrong password"

The thing about the return-statement is,
that it will return the VALUE NO display

We can however capture this return VALUE into a variable myBalance

To call the call the askTeller Method we have to point to
the object containing this Method,
john.askTeller,
as the function was declared with 1-parameter,
you have to provide 1 argument
thus:
john.askTeller(1234)
as we want to capture the return-result we do
var myBalance = john.askTeller(1234)
console.log( myBalance ) will then display 7500.

====================================

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**