Prototype: changeDue(price,paid) requires nonnegative safe integers and paid>=price; return paid-price or raise RangeError.

Final: new VendingMachine(products) copies [code,price,stock] tuples with unique nonempty codes, positive price, and nonnegative stock. Empty inventory valid. insert(amount) requires positive integer, accumulates/returns credit. balance() reads credit. select(code) returns {code,change}, decrements stock once, and clears credit; unknown code, sold out, or insufficient credit raises RangeError unchanged. refund() returns/clears credit and repeats as zero. inventory() returns a fresh plain object keyed by code, with fresh {price,stock} values. No restock.

Every class is exported by name from exercise.mjs. Keep instances independent. Unless explicitly documented otherwise, input values have the stated collection/string types and do not contain null elements. Invalid calls preserve state; validate before mutation. Return fresh mutable snapshots unless stated otherwise.

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.