I understand that these two calls should return the same value. I think the assignment I made is wrong but I don’t see how to do it right.
info2 () returns the correct value while info () does not.
Client.prototype.info2 = function () {
return (this.AccountType())
}
Client.prototype.info = function () {
const {AccountType} = this
return (AccountType())
}
——- All code ——-
function Client(name, balance) {
this.name = name;
this.balance = balance;
}
Client.prototype.AccountType = function () {
const {balance} = this
let type;
if (balance >= 10000) {
type = 'Platinum'
} else if (balance >= 5000) {
type = 'Gold'
} else {
type = 'Standard'
}
return type;
}
//Expected result: 'Gold'
// Result: 'Gold'
Client.prototype.info = function () {
const {AccountType} = this
return (AccountType())
}
//Expected result: 'Gold'
// Result: 'Standard'
Client.prototype.info2 = function () {
return (this.AccountType())
}
//Expected result: 'Gold'
// Result: 'Gold'
//instances
const Pedro = new Client('Pedro', 8000)