The Null Price Latte — JavaScript Bug Hunt

Inspired by the point-of-sale glitches that let customers check out carts full of items with missing prices — for free.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Null Safety, Pricing
  • Modelled on: Starbucks POS
  • Visible tests: known items sum correctly; unknown items throw loudly
  • Reward: 50 XP for a complete fix

Briefing

Inspired by the point-of-sale glitches that let customers check out carts full of items with missing prices — for free. When the menu doesn't know an item, NaN walks straight through the math and the register renders it as $0.00.

register.js must refuse instead.

Bug report

BUG-FREE-LATTE · Priority: High · Reported by: store ops

total(items, menu) — items are { sku, qty }:

  • unknown sku -> throw "Unknown item: <sku>"
  • otherwise sum price * qty in cents

Observed: unknown skus produce NaN, the UI prints $0.00, and word spreads fast.

Logs

[pos] cart=[latte, secret-item] total=NaN -> charged $0.00

The code as shipped

src/pos/register.js (editable)

// Sums a cart against the price menu (cents).
exports.total = function (items, menu) {
  var sum = 0;
  for (var i = 0; i < items.length; i++) {
    sum += menu[items[i].sku] * items[i].qty;
  }
  return sum;
};

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.