Model a bank account with its own owner and balance. The workshop-pass example showed why two instances can share methods without sharing their changing data.
The constructor runs when new BankAccount(...) creates an instance. initialBalance = 0 supplies a default only when that argument is omitted or is undefined. getBalance() is an ordinary method called with parentheses, not a getter property. Getter syntax comes later. The supplied account deposits 50 and withdraws 30 for the final description; other probes use separate accounts so their balances do not interfere.
A deposit changes state but does not need to return a value here. A withdrawal returns a boolean so its caller can tell whether the balance changed. Check the refusal conditions before subtracting. toString() returns a description; it should not log or change the account. This is a learning model, not a production money-handling system.
class WorkshopSession {
constructor(topic, seats) {
this.topic = topic;
this.seats = seats;
}
}
console.log(new WorkshopSession("Testing", 12).topic);
Edit script.js, then use Run to inspect the supplied checkpoints. Use Submit to check your tasks in order. Keep the supplied probes; change only the requested definitions and final logs.
owner and initialBalance in the constructor.getBalance().deposit(amount) to add positive amounts and leave the balance unchanged otherwise.withdraw(amount): return false without changing the balance for nonpositive amounts or insufficient funds; otherwise subtract and return true.toString() in the format BankAccount(owner: Alice, balance: $120) after the supplied transactions.mission result: ; use the account after the supplied deposit and withdrawal.Class syntax: class Name { constructor(...) { this.prop = val; } }
Methods go directly in the class body — no commas between them.
Create instances with new: const obj = new MyClass(args);