Command Palette

Search for a command to run...

Hectal
Phase 6: Classes and Object-Oriented TypeScript
TypeScript · Exercise 2 of 6 PreviousNext
Beginner

Hide the Balance

Wallet lets any code change balance directly. Make it private so only the wallet's own methods can touch it.

Also finish withdraw(n): it takes the money and returns true if the balance is enough, otherwise it changes nothing and returns false. The program should print true false 70.

What Check tests

  1. Your code has no type errors
  2. The console prints true false 70
  3. Reading balance from outside is rejected
  4. Writing balance from outside is rejected
  5. The public methods still work

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.