-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.js
More file actions
49 lines (41 loc) · 1.27 KB
/
Account.js
File metadata and controls
49 lines (41 loc) · 1.27 KB
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
const Dates = require('./Dates');
const dates = new Dates();
class Account {
constructor() {
this.balance = 0;
this.transactions = [];
}
addDeposit(deposit) {
this.balance += deposit.amount;
this.transactions.push({
date: dates.getCurrentDate(),
debit: deposit.amount,
credit: "",
balance: this.balance
});
// return this.balance;
}
subtractWithdrawal(withdrawal) {
if (withdrawal > this.balance) {
throw new Error('Insufficient funds')
}
this.balance -= withdrawal.amount;
this.transactions.push({
date: dates.getCurrentDate(),
debit: "",
credit: withdrawal.amount,
balance: this.balance
});
// return this.balance
}
printStatement() {
let statement = 'date || credit || debit || balance\n'
for (let i = 0; i < this.transactions.length; i++) {
const transaction = this.transactions[i];
statement += `${transaction.date} || ${transaction.credit} || ${transaction.debit} || ${transaction.balance}\n`;
}
console.log(statement)
return statement;
}
}
module.exports = Account;