-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy path4-bank-account.js
More file actions
93 lines (84 loc) · 2.59 KB
/
4-bank-account.js
File metadata and controls
93 lines (84 loc) · 2.59 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* It is time to write some bigger code! You have a bankAccount that is modeled as given.
*
* Finish the two functions that will donate money (donateMoney) and pay rent (payRent).
* If you do not have enough funds, call the onFail function given and don't change the bankAccount.
* If you do have the funds, update the bankAccount accordingly.
*
* TIP: have a look at the test code to get more information on what needs to happen
* TIP: a lot of the things the functions do are the same, you may want to create one or more other functions to not duplicate code
*/
const bankAccount = {
// The currentBalance is how much money you have in your bankAccount.
currentBalance: 250,
// The transactions are a list of changes so that you can keep track.
transactions: [
/**
* The prevAmount is what your balance was before the transaction,
* the newAmount is what your balance was after the transaction
* and the reason is what the transaction was about
*/
{
prevAmount: 350,
newAmount: 250,
reason: "Donation",
},
],
};
const donateMoney = (amount, onSuccess, onFail) => {
// TODO complete this function
};
const payRent = (amount, onSuccess, onFail) => {
// TODO complete this function
};
/**
* TEST CODE. DO NOT EDIT
*/
const onSuccessEnglish = () => {
console.log("Payment successful! Thank you!");
};
const onFailEnglish = () => {
console.log("You do not have enough money to make this payment.");
};
const onSuccessDutch = () => {
console.log("Betaling geslaagd! Dank u!");
};
const onFailDutch = () => {
console.log("U heeft niet voldoende saldo om deze betaling te doen.");
};
donateMoney(100, onSuccessEnglish, onFailEnglish);
console.log(bankAccount);
payRent(100, onSuccessEnglish, onFailEnglish);
console.log(bankAccount);
donateMoney(100, onSuccessDutch, onFailDutch);
console.log(bankAccount);
/**
* The console should print out the following:
Payment successful! Thank you!
{
currentBalance: 150,
transactions: [
{ prevAmount: 350, newAmount: 250, reason: 'Donation' },
{ prevAmount: 250, newAmount: 150, reason: 'Donation' }
]
}
Payment successful! Thank you!
{
currentBalance: 50,
transactions: [
{ prevAmount: 350, newAmount: 250, reason: 'Donation' },
{ prevAmount: 250, newAmount: 150, reason: 'Donation' },
{ prevAmount: 150, newAmount: 50, reason: 'Rent' }
]
}
U heeft niet voldoende saldo om deze betaling te doen.
{
currentBalance: 50,
transactions: [
{ prevAmount: 350, newAmount: 250, reason: 'Donation' },
{ prevAmount: 250, newAmount: 150, reason: 'Donation' },
{ prevAmount: 150, newAmount: 50, reason: 'Rent' }
]
}
*
*/