-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (39 loc) · 1.29 KB
/
index.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
// file: index.js
const readline = require('readline');
const BankTransaction = require('./src/bank_transaction');
const BankStatement = require('./src/bank_statement');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const bankTransaction = new BankTransaction();
const askQuestion = () => {
rl.question('What would you like to do? (deposit, withdraw, print, exit): ', (answer) => {
switch(answer.toLowerCase()) {
case 'deposit':
rl.question('How much would you like to deposit?: ', (amount) => {
bankTransaction.deposit(Number(amount));
askQuestion();
});
break;
case 'withdraw':
rl.question('How much would you like to withdraw?: ', (amount) => {
bankTransaction.withdraw(Number(amount));
askQuestion();
});
break;
case 'print':
const bankStatement = new BankStatement(bankTransaction.transactions);
bankStatement.printStatement();
askQuestion();
break;
case 'exit':
rl.close();
break;
default:
console.log('Invalid command');
askQuestion();
}
});
};
askQuestion();