CHALLENGE
class BankAccount {
#balance;
#transactionLog = [];
constructor(initialBalance) {
this.#balance = initialBalance;
}
deposit(amount) {
this.#balance += amount;
this.#transactionLog.push(`+${amount}`);
return this;
}
withdraw(amount) {
if (amount > this.#balance) throw new Error("Insufficient funds");
this.#balance -= amount;
this.#transactionLog.push(`-${amount}`);
return this;
}
get summary() {
return `Balance: ${this.#balance} | Txns: ${this.#transactionLog.join(", ")}`;
}
}
const account = new BankAccount(100);
account.deposit(50).deposit(25).withdraw(30);
console.log(account.summary);
console.log(account.hasOwnProperty("#balance"));❤2
What is the output?
Anonymous Quiz
13%
true
33%
Balance: 175 | Txns: +50, +25, -30 false
26%
Balance: 145 | Txns: +50, +25, -30
28%
Balance: 145 | Txns: +50, +25, -30 false
🔥3
Please open Telegram to view this post
VIEW IN TELEGRAM
❤2