π¨βπΌ The muffin shop needs a simple receipt that totals an order and prints a
clean summary for customers.
π This example sticks to the skills from the workshop: numbers, strings,
booleans, variables, functions, if/else, switch statements, and loops.
π¨ Open
and complete the following tasks:
- Build the divider string with a loop.
- Calculate
subtotal. - Implement
calculateDiscount. - Implement
calculateTax. - Implement
calculateTip. - Implement
calculatePickupFeewith a switch statement. - Set
pickupLabelwith an if/else. - Set
memberMessagewith an if/else. - Calculate
total. - Make sure the receipt prints with
console.log.
π° Flip
isMember to see the discount and message change.
π° Try pickupMethod as curbside or delivery to test the switch logic.Run the example
npm run start --workspace examples/muffin-shop-checkout
What the output can look like
Here is a sample console receipt output:
================================
Morning Muffins
Order for Avery
--------------------------------
Muffins: 3 x $3.25
Scones: 2 x $4
--------------------------------
Subtotal: $17.75
Discount: -$1.78
Tax: $1.31
Tip: $2.86
Pickup fee: FREE
--------------------------------
Total: $20.14
Member discount applied
================================
Try next
- π¨ Add a
dailySpecialCountanddailySpecialPrice, then include them in thesubtotal. - π¨ Create a
hasCouponboolean and apply an extra discount with anifcheck. - π¨ Use a loop to build a
summaryLinelikeItems: 5 total. - π¨ Add a
rushOrderflag that increases thetipPercentwhen true. - π° Try a new
pickupMethodvalue and update the switch to handle it.