Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef7772e

Browse files
Update ex4-object-shared-methods.js
1 parent 5921e6e commit ef7772e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

Week4/prep-exercises/1-wallet/ex4-object-shared-methods.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ function withdraw(amount) {
1010
return 0;
1111
}
1212

13+
14+
if (this._dayTotalWithdrawals + amount > this._dailyAllowance) {
15+
console.log(`Insufficient remaining daily allowance!`);
16+
return 0;
17+
}
18+
1319
this._cash -= amount;
20+
this._dayTotalWithdrawals += amount;
1421
return amount;
15-
}
22+
};
23+
24+
1625

1726
function transferInto(wallet, amount) {
1827
console.log(
@@ -28,16 +37,32 @@ function reportBalance() {
2837
console.log(
2938
`Name: ${this._name}, balance: ${eurosFormatter.format(this._cash)}`
3039
);
31-
}
40+
};
3241

3342
function getName() {
3443
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+
);
3558
}
3659

3760
function createWallet(name, cash = 0) {
3861
return {
3962
_name: name,
4063
_cash: cash,
64+
_dailyAllowance: 40,
65+
_dayTotalWithdrawals: 0,
4166
deposit,
4267
withdraw,
4368
transferInto,

0 commit comments

Comments
 (0)