forked from DanWahlin/TypeScriptDemos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
48 lines (39 loc) · 1.48 KB
/
main.ts
File metadata and controls
48 lines (39 loc) · 1.48 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
import { CheckingAccount } from './checkingAccount';
import { SavingsAccount } from './savingsAccount';
import { AccountList } from './accountList';
class Bootstrapper {
$(selector: string) {
return document.querySelector(selector);
}
renderAccounts() {
let acctsHtml: string = '';
const accountsDiv = this.$('#accounts');
const checkingAcct = new CheckingAccount('Jane Doe Checking');
const savingsAcct = new SavingsAccount('Jane Doe Savings', 2);
const accList = new AccountList();
accList.add(checkingAcct);
accList.add(savingsAcct);
accList.getAccounts().forEach((acct, index) => {
acctsHtml += acct.title + '<br />';
});
accountsDiv.innerHTML = acctsHtml;
}
renderChecking() {
const account = new CheckingAccount('Jane Doe Checking');
account.deposit(1000);
account.widthdrawal(500);
const div = this.$('#checking').innerHTML = '$' + account.balance.toFixed(2);
}
renderSavings() {
const savings = new SavingsAccount('Jane Doe', 2.5);
savings.deposit(1000);
savings.addInterest();
const savingsDiv = this.$('#savings').innerHTML = '$' +
savings.balance.toFixed(2) +
' (after interest added)';
}
}
const bootstrapper = new Bootstrapper();
bootstrapper.renderAccounts();
bootstrapper.renderChecking();
bootstrapper.renderSavings();