Quick actions

cmd+k|ctrl+k

Navigation

Languages

Class - Js

Snippet info

Language

JavaScript

Visibility

public

Author

yusuphmdoe1

Created

2025-01-15T11:30:23.847442Z

Updated

2025-01-15T11:32:42.600082Z

class BankAccount {
    constructor(name, accountNumber, balance) {
        this.name = name;
        this.accountNumber = accountNumber;
        this.balance = balance;
    }

    deposit(amount) {
        
        if (amount > 0) {
            this.balance += amount;
        } else {
            throw new Error("Deposit amount must be positive.");
        }
    }

    withdraw(amount) {
    
        if (amount > 0) {
            if (amount <= this.balance) {
                this.balance -= amount;
            } else {
                throw new Error("Insufficient funds for this withdrawal.");
            }
        } else {
            throw new Error("Withdrawal amount must be positive.");
        }
    }

    getBalance() {
    
        return this.balance;
    }
    
    getAccountDetails() {
    
        return "Account Holder: " +this.name;
    }
}

// Example usage:
 const account = new BankAccount("YUSUPH MDOE", "40052258006", 1500.0);
 account.deposit(200.0);
 console.log(account.getBalance()); 
 account.withdraw(100.0);
 console.log(account.getBalance()); 
 console.log(account.getAccountDetails()); 
 
 
 
INFO