46.2 - Parcel Delivery Calculator, part 2 — extra complexity (JS lessons — arguments and return)
📘 Task: Parcel Delivery Calculator 2.0
This is a continuation of the previous task. The architecture stays the same — the same
4 functions (3 calculators + 1 main), the function signatures don't change.
Only what happens inside the three calculator functions changes.
🧩 Main condition
Only touch the logic inside calculateWeightCost,
calculateDistanceCost and calculateUrgentSurcharge.
The main function calculateTotalCost() — stays unchanged.
💰 New rates (hardcoded as constants):
- 📦 Base fee — 15 $ (unchanged)
- ⚖️ Weight: if the parcel is heavier than 10 kg — rate 2 $/kg (discount for heavy parcels),
if 10 kg or less — regular rate 3 $/kg
- 📏 Distance: if the delivery is farther than 15 km — rate 1.5 $/km (discount for long distances),
if 15 km or less — regular rate 2 $/km
- 🚀 Urgency surcharge: if express and the amount is greater than 60 $ — +15% (slightly
lower surcharge for large orders); if express and the amount is 60 $ or less — +25%; not express — no surcharge