-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_BankAccount.js
32 lines (30 loc) · 1.21 KB
/
4_BankAccount.js
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
// Write a JavaScript program that creates a class called "BankAccount" with properties for account number and balance. Include methods to deposit and withdraw money from the account. Create some instances of the "BankAccount" class, deposit some money, and withdraw a portion of it.
class BankAcccount {
constructor(acc_num, balance) {
this.acc_num = acc_num;
this.balance = balance;
console.log(`Account Number : ${this.acc_num}\nAccount Opening Amount ${this.balance}`)
}
deposite(deposite_amount) {
this.balance += deposite_amount
return (`updated balance is ${this.balance}`)
}
withdraw(withdraw_amount) {
if (this.balance < withdraw_amount) {
return (`Amount is not sufficient in your account`)
} else {
this.balance -= withdraw_amount;
return (`updated balance is ${this.balance}`)
}
}
displayBalance() {
return (`Account Balance: ${this.balance}`);
}
}
const obj = new BankAcccount(22161, 200);
console.log(obj.deposite(20))
console.log(obj.withdraw(40))
console.log(obj.displayBalance());
console.log(obj.deposite(50))
console.log(obj.withdraw(60))
console.log(obj.displayBalance());