Cart total with a coupon

A code exercise of about 15 minutes: read the statement, solve «Cart total with a coupon» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

Write cartTotal(items, coupon?). Each line has price (in cents) and qty. The coupon can be { type: "percent", value } (percentage off the subtotal) or { type: "fixed", value } (cents). Return the total in cents, rounded to the nearest cent and never negative. Lines with qty of 0 or less don't count.