Tell us what’s happening:
I am not passing tests 20 and 21. Everything seems to functioning just fine, I’ve tried to debug but with no success.
Your code so far
class BankAccount {
constructor(){
this.balance = 0;
this.transactions = [];
this.type = '';
}
deposit(amount){
if(amount > 1){
this.type = "Deposit";
this.balance = amount + this.balance;
this.transactions.push({type: this.type, amount: amount});
const depositString = `Successfully deposited $${amount}. New balance: $${this.balance}`;
return depositString;
}else{
return `Deposit amount must be greater than zero.`;
}
}
withdraw(amount){
const negative = (this.balance - amount);
if(this.balance < amount || amount <= 0 || negative < 0){
const notEnoughMoney = "Insufficient balance or invalid amount.";
return notEnoughMoney;
} else{
this.type = "Withdraw";
this.balance = this.balance - amount;
this.transactions.push({type: this.type, amount: amount});
const withdrawString = `Successfully withdrew $${amount}. New balance: $${this.balance}`;
return withdrawString;
}
}
checkBalance(){
return `Current balance: $${this.balance}`;
}
listAllDeposits(){
let allDeposits = this.transactions.filter((item) => item.type === "Deposit");
const array = [];
allDeposits.forEach(item => array.push(item.amount));
return `Deposits: ${array}`;
};
listAllWithdrawals(){
let allWithdrawals = this.transactions.filter((item) => item.type === "Withdraw");
const array = [];
allWithdrawals.forEach(item => array.push(item.amount));
return `Withdrawals: ${array}`;
};
};
const myAccount = new BankAccount();
console.log(myAccount.deposit(100));
console.log(myAccount.deposit(200));
console.log(myAccount.deposit(150));
console.log(myAccount.deposit(0));
console.log(myAccount.withdraw(25));
console.log(myAccount.withdraw(50));
console.log(myAccount.withdraw(1000));
console.log(myAccount.checkBalance());
console.log(myAccount.listAllDeposits());
console.log(myAccount.listAllWithdrawals());
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0
Challenge Information:
Build a Bank Account Management Program - Build a Bank Account Management Program
https://www.freecodecamp.org/learn/full-stack-developer/lab-bank-account-manager/build-a-bank-account-management-program