Compute shipping cost for an order
Node · Node · advanced · greenfield
Adds shipping-cost calculation. Standard shipping is $5 and becomes free at a $50 subtotal; express adds a flat $12 and always applies regardless of the free-shipping threshold. Covered the boundary at exactly $50 and the express-plus-free-standard case.
Requirements
- Shipping is a flat $5.
- Orders with a subtotal of $50 or more ship free.
- Express shipping adds $12 on top, and is never free (it applies even when standard shipping would be free).
- Return the shipping cost in whole dollars as a number.
Files touched
- src/checkout/shipping.js
--- src/checkout/shipping.js
+function shippingCost(subtotal, express) {
+ let cost = subtotal >= 50 ? 0 : 5;
+ if (express) {
+ cost += 12;
+ }
+ return cost;
+}
+
+module.exports = { shippingCost };