Tell us what’s happening:
Not able to get the test case #17 passed.
- 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