MCPcopy Create free account
hub / github.com/CleverProgrammers/JavaScript-Course-by-Clever-Programmer- / Bank

Class Bank

classes/banksClass/script.js:1–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Bank {
2 constructor(balance) {
3 this.balance = balance
4 }
5
6 withdraw(amount) {
7 // guard clause
8 if (this.balance - amount <= 0) {
9 console.log('❌ You cannot withdraw more than what you have!')
10 console.log({balance: this.balance})
11 return
12 }
13
14 this.balance -= amount
15 console.log('withdrew', `$${amount}`)
16 console.log({balance: this.balance})
17 }
18
19 deposit(amount) {
20 this.balance += amount
21 console.log('deposited', `$${amount}`)
22 console.log({balance: this.balance})
23 }
24}
25
26const qaziChecking = new Bank(0)
27// console.log(qaziChecking.balance)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected