The equipment desk demo showed guarded checkout behavior inherited by a specialized class. The private field still belongs to the base class and cannot be read directly by the child. Now build a library checkout system from scratch in script.js. Books record authors and describe their own availability. All results go to the Console, not a page element.
LibraryItem owns the private status; Book inherits checkout and return behavior. The checkpoints make it possible to inspect transitions after each operation. Do not expose the private field directly or write book.#checkedOut outside the class.
A different private-state class exposes behavior without exposing its field:
class Lamp {
#on = false;
switchOn() { this.#on = true; }
get isOn() { return this.#on; }
}
const lamp = new Lamp();
lamp.switchOn();
console.log(lamp.isOn); // true
LibraryItem constructor. The starter checks its title.available getter using the initial private #checkedOut state. The starter checks a new item.Book while inheriting from LibraryItem. The starter checks the author.checkout() to mark an available book on loan and return true. The starter checks the result and availability.false without changing availability. The starter checks the repeated call.returnItem() to restore availability and return true. The starter checks the result.false. The starter checks the repeated call.Book.describe() to return River Atlas by N. Vale — available after the return. The starter logs it.You can model shared behavior and protect state while still exposing useful operations. Take the quiz to check where each responsibility belongs.
Call super(title) before assigning the book author.
Keep the loan state in #checkedOut; change it only inside methods.
Return false for an invalid checkout or return without changing state.