-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop.js
54 lines (50 loc) · 1.61 KB
/
oop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var bankAccount = function(custName, acctNumber, acctType){
this.custName = custName;
this.acctNumber = acctNumber;
this.acctType = acctType;
this.balance = 0;
};
bankAccount.prototype.deposit = function(amount){
if(amount <= 0){
return "Invalid deposit amount";
}
else{
this.balance += amount;
return this.balance;
}
};
bankAccount.prototype.withdraw = function(){
if(this.balance - amount < this.minimumBalance){
return "Cannot withdraw beyond the current account balance";
}
else if(amount > this.balance){
return "Cannot withdraw beyond the current balance";
}
else if(amount <= 0){
return "Invalid withdraw amount";
}
else{
this.balance -= amount;
return this.balance;
}
};
bankAccount.prototype.displayBalance = function(){
console.log("Your account balance is " +this.balance );
};
bankAccount.prototype.accountDetails = function(){
console.log("Account name: " +this.custName+ " Account number: " +acctNumber+ " Account balance: " +this.balance );
};
var savingsAccount = function (custName, acctNumber, minimumBalance){
bankAccount.call(this, custName, acctNumber);
this.minimumBalance = 1000;
this.balance = this.minimumBalance;
}
savingsAccount.prototype = Object.create(bankAccount.prototype);
savingsAccount.prototype.constructor = savingsAccount;
var currentAccount = function(custName, acctNumber, minimumBalance){
bankAccount.call(this, custName, acctNumber);
this.minimumBalance = 5000;
this.balance = this.minimumBalance;
}
currentAccount.prototype = Object.create(bankAccount.prototype);
currentAccount.prototype.constructor = currentAccount;