question 38 Conditional Logic · medium
Price a cart with a coupon code
A checkout accepts two coupon codes. WELCOME10 takes 10% off the subtotal. FREESHIP makes shipping free. No code (empty text) means no coupon. Any other code prints Unknown coupon: and the code, and then works like no coupon. Shipping is 5, but free when the subtotal after the discount is 50 or more. Use match for the codes, then print the discount, the shipping and the total.
First lines
subtotal = 60 and coupon = "WELCOME10". Check runs your program again with other cartsPrints
Discount: 6.0, Shipping: 0, Total: 54.0Discountalways computed as subtotal × percent / 100, so it prints as a decimal,
0.0 with no couponExpected output3 lines
- 1Discount: 6.0
- 2Shipping: 0
- 3Total: 54.0