-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccount.js
28 lines (26 loc) · 893 Bytes
/
BankAccount.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
class BankAccount {
constructor(){
this.balance = 0;
this.transaction = []
}
getBalance() {
return this.balance
}
deposit(number) {
if (number <= 0 || number >= 10000) {
throw new Error('Invalid deposit amount')
}
this.balance += number;
const transaction = { date: new Date().toLocaleDateString(), credit: number, debit: null, balance: this.balance}
this.transaction.push(transaction)
}
withdraw(number) {
if (number <= 0 || number > this.balance || number >= 10000) {
throw new Error('Invalid withdrawal amount')
}
this.balance -= number;
const transaction = { date: new Date().toLocaleDateString(), credit: null, debit: number, balance: this.balance }
this.transaction.push(transaction)
}
}
module.exports = BankAccount;