24/30 Am I doing something wrong?


#1

Somehow I can't print John's bankBalance. Can someone tell me what's wrong with this code?


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

this.getBalance = function(bankBalance) {
// your code should return the bankBalance
bankBalance = john.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(myBalance)


#3

your getBalance() method does not require an argument.
By assigning john.bankBlance; into bankBalance, you're making its value "undefined";
just simpley return "bankbalance"

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

this.getBalance = function() { <------takes no arguments
// your code should return the bankBalance
return bankBalance; <------return bankBalance whose value is already assigned 7500.
};
}

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


#4

Thanks unimog,

That worked for me, I forgot to enter:

var myBalance = john.getBalance();
console.log(myBalance);

instead I entered:

var myBalance = john.bankBalance;
console.log(myBalance);

which was wrong.