Practice · 1 of 2
Design a Module's Public API
CHALLENGE
Difficulty: intermediate+25 XP
Write a module object for a cart library. Define createCart() that returns an object exposing exactly three methods — add(item), total(), clear() — and NO direct access to the items array.
add accepts { name, price } and returns the new item count. total() returns the sum of prices. clear() empties the cart.
Press Submit to check your solution.
Back to lesson: Practice: Designing Module Boundaries — Practice