-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile4.js
More file actions
46 lines (37 loc) · 770 Bytes
/
file4.js
File metadata and controls
46 lines (37 loc) · 770 Bytes
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
class account {
#bal;
constructor(initBal) {
this.#bal = initBal;
}
deposit(amt) {
if (amt > 0) {
this.#bal += amt;
console.log(`deposited: ${amt}`);
} else {
console.log('deposit amount must be positive');
}
}
withdraw(amt) {
if (amt > 0 && amt <= this.#bal) {
this.#bal -= amt;
console.log(`withdrew: ${amt}`);
} else {
console.log('invalid withdraw amount');
}
}
getbal() {
console.log(`current balance: ${this.#bal}`);
return this.#bal;
}
}
function main() {
const acc = new account(100);
acc.getbal();
acc.deposit(50);
acc.getbal();
acc.withdraw(30);
acc.getbal();
acc.withdraw(150);
acc.getbal();
}
main();