Practice ยท 1 of 2
Design a Module's Public API
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.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Designing Module Boundaries โ Practice