Last active
October 9, 2021 18:05
-
-
Save jim-clark/e3fc426d73153fac6dc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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