π¨βπΌ 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 helpers and values
below. Fixture inputs (
muffinCount, prices, taxRate, tipPercent,
isMember, pickupMethod, and so on) are already in the file.Business rules
- Divider lines:
buildDividerbuilds the=/-banner lines by repeating a character to a given length. - Money display:
formatMoneyformats an amount with a leading$(for example3.25displays as$3.25, and4as$4). - Subtotal: sum of each line item (quantity Γ unit price for muffins and scones).
- Member discount: members get 10% off when the subtotal is at least
$15; otherwise the discount is$0. - Tax: applied to the amount after the discount, using
taxRate. - Tip: applied to the post-discount subtotal plus tax, using
tipPercent. - Pickup fee (use a
switchonpickupMethod):counterβ$0curbsideβ$3deliveryβ$7
- Pickup label: show
FREEwhen the fee is$0; otherwise show the fee withformatMoney. - Member message:
Member discount appliedfor members, otherwiseJoin the club for 10% off. - Total: subtotal, minus discount, plus tax, tip, and pickup fee.
- Print the assembled
receiptwithconsole.log.
Success criteria (default fixtures)
With the starter defaults (
isMember = true, pickupMethod = 'counter', etc.),
your printed receipt should match this shape and the sample numbers below:================================
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
================================
(Floating-point display may vary slightly; the structure and labels must match.)
π° 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 extra_muffin-shop-checkout
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.