JavaScript · Intermediate · Ticket 1Ticket #19 · from Lena Fischer, Finance & Ops
  1. Example
  2. Warm-up 1
  3. Warm-up 2
  4. Ticket
Brief
NEW TICKET#19 · Checkout

Coupon: percent or fixed, capped, never below zero

Lena Fischer · Finance & Ops
Opened today

“A customer put a $15 coupon on a $10 add-on, and the invoice said we owe them $5.00. A total can never go below zero. While you're in there: our percent coupons are sold as "20% off, up to $50", and that cap (maxOff) isn't applied at all, so a $400 order got $80 off. And a percentage should round to the nearest cent; we're sending invoices with $149.85 discounts on $999 orders. Can you fix applyCoupon?”

YOUR PLAN
  1. 1Watch an example2 min
  2. 2Warm-up 11 min
  3. 3Warm-up 21 min
  4. 4Fix the ticket11 min
BY THE END YOU CAN
  • Keep a number from going below zero with Math.max
  • Cap a number with Math.min
  • Round money to whole cents at the right moment
About 15 minutes
Four short steps. Nothing is timed, and you can leave any time.