Let and Const

Let and Const
πŸ‘¨β€πŸ’Ό We're building a shopping cart system. Some values will change as users interact (like the cart total), while others stay constant (like tax rates and product prices).
🐨 Open
index.ts
and:
  1. Create a const named TAX_RATE set to 0.08
  2. Create a let named cartTotal starting at 0
  3. Create const product prices with these exact values:
    • bookPrice = 15.99
    • muffinPrice = 4.5
    • laptopPrice = 999.99
  4. Add the book and the muffin to the cart by updating cartTotal (do not add the laptop for this step)
  5. Create finalTotal as the cart subtotal plus 8% tax (TAX_RATE)
  6. Try to reassign TAX_RATE (keep it commented after you see the TypeScript error) and export your results

Required exports

Export these names so the tests can verify your work:
  • TAX_RATE
  • cartTotal
  • finalTotal

Completion criteria (with the fixtures above)

  • TAX_RATE is 0.08
  • cartTotal is 20.49 (book + muffin only)
  • finalTotal is 22.1292 (subtotal + 8% tax)
πŸ’° By convention, constants that represent fixed values are often UPPER_CASE:
const MAX_ITEMS = 100
const API_URL = 'https://api.example.com'
πŸ“œ MDN - const
This is the first exercise where you'll be exporting values for the tests! For a reminder on how to do that, check out the previous page.

Please set the playground first

Loading "Let and Const"
Loading "Let and Const"