Drill

ProblemsJavaScript › billing

Compute the final charge on an order

easybillingJavaScript

Combine a subtotal, an optional discount, and shipping to produce the final amount due.

finalCharge(subtotal: int, discount: int, shipping: int) → int

Solve it in the editor →

Where you start

function finalCharge(subtotal, discount, shipping) {
  
}

Worked examples

CallResult
finalCharge(5000, 500, 800)5300
finalCharge(1000, 2000, 500)500
finalCharge(3000, 0, 1000)4000
finalCharge(0, 0, 0)0

Hint

Max(0, subtotal − discount) then add shipping.

Reference solution in JavaScript
function finalCharge(subtotal, discount, shipping) {
  const net = subtotal > discount ? subtotal - discount : 0;
  return net + shipping;
}

The same problem in another language

More billing problems in JavaScript