πŸ‘¨β€πŸ’Ό 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
index.ts
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: buildDivider builds the = / - banner lines by repeating a character to a given length.
  • Money display: formatMoney formats an amount with a leading $ (for example 3.25 displays as $3.25, and 4 as $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 switch on pickupMethod):
    • counter β†’ $0
    • curbside β†’ $3
    • delivery β†’ $7
  • Pickup label: show FREE when the fee is $0; otherwise show the fee with formatMoney.
  • Member message: Member discount applied for members, otherwise Join the club for 10% off.
  • Total: subtotal, minus discount, plus tax, tip, and pickup fee.
  • Print the assembled receipt with console.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 dailySpecialCount and dailySpecialPrice, then include them in the subtotal.
  • 🐨 Create a hasCoupon boolean and apply an extra discount with an if check.
  • 🐨 Use a loop to build a summaryLine like Items: 5 total.
  • 🐨 Add a rushOrder flag that increases the tipPercent when true.
  • πŸ’° Try a new pickupMethod value and update the switch to handle it.

Please set the playground first

Loading "Muffin Shop Checkout"