Command Palette

Search for a command to run...

Hectal
Phase 2: Operators and Control Flow
JavaScript · Exercise 3 of 5 PreviousNext
Beginner

Shipping zones

Write shippingCost(zone): "local" costs 40, "national" costs 80 and "international" costs 250. Any other zone returns null, including tricky names like "constructor" and "toString".

Then write finalShipping(zone, orderTotal): orders of 500 or more ship free (0) to local and national zones; international always pays its normal cost; unknown zones still return null.

Use a switch or a lookup table: your choice.

What Check tests

  1. Known zones cost 40, 80 and 250
  2. Unknown zones return null
  3. Inherited names like constructor aren't zones
  4. Local and national orders of 500+ ship free
  5. Smaller orders and international orders pay
  6. Unknown zones stay null even for big orders

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.