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

Tell us what’s happening:

I have called the withdraw method twice as asked but it doesn’t seem to pass. Can anybody take a look at this?

Your code so far

class BankAccount{
  constructor(){
  this.balance=0;
  this.transactions=[];    
  }
  deposit(amount){
    if(amount>0){
      this.transactions.push({"type":"deposit", amount: amount})
      this.balance+=amount;
      return `Successfully deposited $${amount}. New balance: $${this.balance}`;
    }
    else{
      return "Deposit amount must be greater than zero."
    }
  }
  withdraw(amount){
    if(amount>0&&amount<=this.balance){
      this.transactions.push({"type":"withdrawal", amount})
      this.balance-=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(tr => tr.type === 'deposit')
    .map(tr => tr.amount)
    .join(',');
  return `Deposits: ${deposits}`;
}
listAllWithdrawals() {
  const withdrawals = this.transactions
    .filter(tr => tr.type === 'withdrawal')      
    .map(tr => tr.amount)                      
    .join(',');                              
  return `Withdrawals: ${withdrawals}`;
}
}
const myAccount=new BankAccount();
myAccount.deposit(100)
myAccount.deposit(50)
myAccount.withdraw(10)
myAccount.deposit(500)
myAccount.withdraw(100)
myAccount.withdraw(10)
console.log(myAccount.withdraw(100));

Your browser information:

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

Challenge Information:

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

The type property should be either deposit or withdraw ,

your implementation doesn’t match the requirements

thank you very much. this passed the test