-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (44 loc) · 1.36 KB
/
script.js
File metadata and controls
51 lines (44 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Bank {
constructor(balance) {
this.balance = balance
}
withdraw(amount) {
// guard clause
if (this.balance - amount <= 0) {
console.log('❌ You cannot withdraw more than what you have!')
console.log({balance: this.balance})
return
}
this.balance -= amount
console.log('withdrew', `$${amount}`)
console.log({balance: this.balance})
}
deposit(amount) {
this.balance += amount
console.log('deposited', `$${amount}`)
console.log({balance: this.balance})
}
}
const qaziChecking = new Bank(0)
// console.log(qaziChecking.balance)
// qaziChecking.deposit(10000)
// qaziChecking.deposit(10000)
// qaziChecking.deposit(10000)
// qaziChecking.withdraw(1000)
// qaziChecking.withdraw(20000)
// qaziChecking.withdraw(5000)
// qaziChecking.withdraw(5000)
const depositButton = document.getElementById('deposit')
const withdrawButton = document.getElementById('withdraw')
const amountInput = document.getElementById('amount')
const balanceDiv = document.getElementById('balance')
depositButton.onclick = () => {
const amount = Number(amountInput.value)
qaziChecking.deposit(amount)
balanceDiv.innerText = `Balance: ${qaziChecking.balance}`
}
withdrawButton.onclick = () => {
const amount = Number(amountInput.value)
qaziChecking.withdraw(amount)
balanceDiv.innerText = `Balance: ${qaziChecking.balance}`
}