Skip to content

Instantly share code, notes, and snippets.

@jim-clark
Last active October 9, 2021 18:05
Show Gist options
  • Save jim-clark/e3fc426d73153fac6dc1 to your computer and use it in GitHub Desktop.
Save jim-clark/e3fc426d73153fac6dc1 to your computer and use it in GitHub Desktop.
function BankAccount(ownerName, begBalance) {
var accountNumber = new Date().getTime() + '';
this.ownerName = ownerName;
this.balance = begBalance;
this.getAccountNumber = function() { return accountNumber; };
}
BankAccount.prototype.deposit = function(amount) {
this.balance += amount;
return this.balance;
};
BankAccount.prototype.withdraw = function(amount) {
this.balance -= amount;
return this.balance;
};
function CheckingAccount(ownerName, begBalance, overdraftEnabled) {
BankAccount.call(this, ownerName, begBalance);
this.overdraftEnabled = overdraftEnabled || false;
}
CheckingAccount.prototype = Object.create(BankAccount.prototype);
CheckingAccount.prototype.constructor = CheckingAccount;
CheckingAccount.prototype.orderChecks = function() { return 'Checks have been ordered for Account: ' + this.getAccountNumber(); };
CheckingAccount.prototype.withdraw = function(amount) {
if ( this.overdraftEnabled || amount <= this.balance ) {
this.balance -= amount;
return this.balance;
} else {
return "NSF";
}
};
var chkAcct = new CheckingAccount('Joe Smith', 100, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment