Quick actions

cmd+k|ctrl+k

Navigation

Languages

class JS

Snippet info

Language

JavaScript

Visibility

public

Author

yusuphmdoe1

Created

2025-01-15T11:32:52.27677Z

Updated

2025-01-15T14:08:32.257876Z

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

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

    withdraw(amount) {
    
        
       if (amount <= this.balance) 
       {
          this.balance -= amount;
       } else {
           console.log("Insufficient funds for this withdrawal.");
       }
            
    }

    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(10000.0);
//  console.log(account.getBalance()); 
//  console.log(account.getAccountDetails()); 
 
 
 
INFO