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

Tell us what’s happening:

Not able to get the test case #17 passed.

  1. When you withdraw 20, 50, 100, the listAllWithdrawals method should return “Withdrawals: 20,50,100”.

the console log output appears to satisfy the requirement but the test is failing.
console log output of firstAccount.listAllWithdrawals()
Withdrawls: 20,50,100

Your code so far

class BankAccount {
  constructor(balance=0) {
    this.balance = balance;
    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: "withdraw",
          amount: 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 depositAmountsString = this.transactions
    .filter(transaction => transaction.type === "deposit")
    .map(transaction => transaction.amount)
    .join(",");
    return `Deposits: ${depositAmountsString}`
  }

  listAllWithdrawals() {
    const withdrawlAmountsString = this.transactions
    .filter(transaction => transaction.type === "withdraw")
    .map(transaction => transaction.amount)
    .join(",");
    return `Withdrawls: ${withdrawlAmountsString}`
  }

}

const myAccount = new BankAccount();
console.log(myAccount.deposit(10));
console.log(myAccount.deposit(35));
console.log(myAccount.deposit(90));

console.log(myAccount.deposit(200));

console.log(myAccount.withdraw(20));
console.log(myAccount.withdraw(50));
console.log(myAccount.withdraw(100));

console.log(myAccount.checkBalance());

console.log(myAccount.listAllDeposits());
console.log(myAccount.listAllWithdrawals());

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:148.0) Gecko/20100101 Firefox/148.0

Challenge Information:

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

You have just misspelled “Withdrawals:”.

thanks @dhess

I suspect I must have typos and checked multiple times but could not figure out.
corrected the typo and the test passed.

Even a single punctuation mistake, can cause a log and may be troubleshooting for you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.