Prototype: implement class Document(id, title) with setTitle(title) and snapshot(). id is a nonempty string; title is a string (including empty). Invalid values throw RangeError. setTitle returns true only when the title changes. snapshot returns a new {id, title} object; callers cannot change internal state through it.

Final: implement VersionedDocument extends Document. Start at version 1. Inherit the same validation and update behavior; increment version once per accepted title change, never on a no-op or rejection. snapshot returns a new {id, title, version} object. Instances are independent.

Complete the exported stubs in exercise.mjs. The prototype and final stages have separate checks.

Shell
node main.mjs --stage prototype
node main.mjs --stage final

Use Node.js 20+ locally, or the website's browser worker. Tests are standard-library only and check the documented behavior; they do not prove performance or force garbage collection.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.