JavaScript Bank exercise

parent d8f9d980
class Bank{
constructor() {
this.customers = {};
}
};
Bank.prototype.addCustomer = function(customer) {
this.customers[customer] = 0;
}
let bank = new Bank();
bank.addCustomer('Sheldon');
Bank.prototype.printAccount = function(customer) {
console.log(`${customer} account is ${this.customers[customer]}`);
}
Bank.prototype.deposit = function(customer, money) {
this.customers[customer] = this.customers[customer] + money;
}
Bank.prototype.withdraw = function(customer, money) {
if (this.customers[customer] >= money) {
this.customers[customer] = this.customers[customer] - money;
}
else {
console.log('Sorry, not enough nomey on the account.'); // exercise onus feature
}
}
Bank.prototype.listOfClients = function() { // exercise bonus feature
console.log(bank.customers);
}
bank.addCustomer('Sheldon');
bank.printAccount('Sheldon');
bank.deposit('Sheldon', 10);
bank.printAccount('Sheldon');
bank.addCustomer('Raj');
bank.printAccount('Raj');
bank.deposit('Raj', 10000);
bank.printAccount('Raj');
bank.withdraw('Raj', 100);
bank.printAccount('Sheldon'); // print 'Sheldon account is 10'
bank.printAccount('Raj'); // print 'Raj account is 9900'
bank.listOfClients();
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment