Build a Bank Account Management Program - Build a Bank Account Management Program

Tell us what’s happening:

im failing test 21 and ive tried the solutions on the forum

Your code so far

class BankAccount {
  constructor() {
    this.balance = 0;
    this.transactions = [];
  }

  deposit(amount) {
    if (amount > 0) {
      this.balance += amount;
      this.transactions.push({ type: 'deposit', amount });
      return `Successfully deposited $${amount}. New balance: $${this.balance}`;
    } else {
      return 'Deposit amount must be greater than zero.';
    }
  }

  withdraw(amount) {
    if (amount > 0 && this.balance >= amount) {
      this.balance -= amount;
      this.transactions.push({ type: 'withdrawal', amount });
      return `Successfully withdrew $${amount}. New balance: $${this.balance}`;
    } else {
      return 'Insufficient balance or invalid amount.';
    }
  }

  checkBalance() {
    return `Current balance: $${this.balance}`;
  }

  listAllDeposits() {
    const deposits = this.transactions.filter(transaction => transaction.type === 'deposit').map(transaction => transaction.amount);
    return `Deposits: ${deposits.join(',')}`;
  }

  listAllWithdrawals() {
    const withdrawals = this.transactions.filter(transaction => transaction.type === 'withdrawal').map(transaction => transaction.amount);
    return `Withdrawals: ${withdrawals.join(',')}`;
  }
}

const myAccount = new BankAccount();

myAccount.deposit(200);
myAccount.withdraw(20);
myAccount.deposit(50);
myAccount.withdraw(20);
myAccount.deposit(50);
myAccount.withdraw(50);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Build a Bank Account Management Program - Build a Bank Account Management Program

Welcome to the forum @lecooda24best .

Each transaction stored in the transactions array should be an object with two properties: type and amount . The type property should be either deposit or withdraw

Please read carefully the expected types for the transactions object.