HomeChallengesRepsProblemsLeaderboardTake a challenge

Shopping Cart

A cart with rules: no duplicate lines, quantities that cannot reach zero, and a total that is always right.

Beginner15 min on the clock6 graded checks · 100 pointsJavaScript + TypeScript
Graded by running your code against real cases.

What you build

  • addToCart(productId) — adds a line, or increments the one already there
  • removeFromCart(productId) — takes the line out entirely
  • increaseQuantity(productId) / decreaseQuantity(productId)
  • Quantity must never drop below 1
  • getCartTotal() — price times quantity, summed

Done means

Adding the same product twice gives one line of quantity 2, and no quantity can reach zero.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. addToCart adds a line with quantity 1+15Enforcing the rules of your data
  2. Adding the same product twice does not duplicate it+20Enforcing the rules of your data
  3. removeFromCart takes the line out completely+15Enforcing the rules of your data
  4. increaseQuantity bumps an existing line+10Enforcing the rules of your data
  5. decreaseQuantity never goes below 1+20Enforcing the rules of your data
  6. getCartTotal multiplies before it sums+20Array methods

What it teaches

The rest of JavaScript + TypeScript