File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
Week4/prep-exercises/1-wallet Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,18 @@ function withdraw(amount) {
10
10
return 0 ;
11
11
}
12
12
13
+
14
+ if ( this . _dayTotalWithdrawals + amount > this . _dailyAllowance ) {
15
+ console . log ( `Insufficient remaining daily allowance!` ) ;
16
+ return 0 ;
17
+ }
18
+
13
19
this . _cash -= amount ;
20
+ this . _dayTotalWithdrawals += amount ;
14
21
return amount ;
15
- }
22
+ } ;
23
+
24
+
16
25
17
26
function transferInto ( wallet , amount ) {
18
27
console . log (
@@ -28,16 +37,32 @@ function reportBalance() {
28
37
console . log (
29
38
`Name: ${ this . _name } , balance: ${ eurosFormatter . format ( this . _cash ) } `
30
39
) ;
31
- }
40
+ } ;
32
41
33
42
function getName ( ) {
34
43
return this . _name ;
44
+ } ;
45
+
46
+ function resetDailyAllowance ( ) {
47
+ this . _dayTotalWithdrawals = 0 ;
48
+ console . log ( `${ this . _name } 's daily withdrawals have been reset.` ) ;
49
+ }
50
+
51
+ function setDailyAllowance ( newAllowance ) {
52
+ this . _dailyAllowance = newAllowance ;
53
+ console . log (
54
+ `${ this . _name } 's daily allowance set to: ${ eurosFormatter . format (
55
+ newAllowance
56
+ ) } `
57
+ ) ;
35
58
}
36
59
37
60
function createWallet ( name , cash = 0 ) {
38
61
return {
39
62
_name : name ,
40
63
_cash : cash ,
64
+ _dailyAllowance : 40 ,
65
+ _dayTotalWithdrawals : 0 ,
41
66
deposit,
42
67
withdraw,
43
68
transferInto,
You can’t perform that action at this time.
0 commit comments