Pocket Money Wallet
JavaScript
20 pts
Pocket Money Wallet
Write a class Wallet:
constructor(owner)saves the owner and startsbalanceat0.deposit(amount)adds the amount to the balance.spend(amount): if the amount is bigger than the balance, change nothing and returnfalse; otherwise subtract it and returntrue.report()returns text likeSelam has 35 Nakfa.
Then create Selam’s wallet, deposit 50, and print spend(15), spend(100), report() and the wallet. Expected output:
true
false
Selam has 35 Nakfa
{ owner: "Selam", balance: 35 }
Checklist
- A
Walletsaves its owner and starts with balance 0. deposit(amount)adds money.spend(amount)refuses (returnsfalse) when there is not enough money, else subtracts and returnstrue.report()returns the owner and balance as text.- Run Selam’s example and print the four results.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
