0% found this document useful (0 votes)
5 views1 page

New Text Document

frcfddf

Uploaded by

ds1997benghazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

New Text Document

frcfddf

Uploaded by

ds1997benghazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class BankAccount {

constructor(accountNumber, accountHolderName, balance) {


this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.balance = balance;
}
deposit(amount) {
this.balance += amount;
console.log(`Amount $${amount} deposited into account ${this.accountNumber}.`);
}

withdraw(amount) {
if (amount <= this.balance) {
this.balance -= amount;
console.log(`Amount $${amount} withdrawn from account $
{this.accountNumber}.`);
} else {
console.log(`Insufficient balance in account ${this.accountNumber}.`);
}
}

transfer(amount, recipientAccount) {
if (amount <= this.balance) {
this.balance -= amount;
recipientAccount.deposit(amount);
console.log(`Amount $${amount} transferred from account ${this.accountNumber}
to account ${recipientAccount.accountNumber}.`);
} else {
console.log(`Insufficient balance in account ${this.accountNumber} for
transfer.`);
}
}

displayBalance() {
console.log(`Account ${this.accountNumber} balance: $${this.balance}`);
}
}

// Create multiple instances of the BankAccount class


const account1 = new BankAccount('SB-012', 'Karishma Hedy', 4);
const account2 = new BankAccount('SB-019', 'Phokas Intan', 2);

You might also like