Loading lesson…
Level 1 · Apprentice0 XP
Swap behaviour by passing it in, so new cases need no edits to old code.
Step 1 / 5
ProblemShipping cost depends on the carrier. Every new carrier means editing this function, retesting every branch and risking the old ones.
← → step
Before this: Testing, tooling and unsafe
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write a discount calculator with three rules (none, 10% for members, 5 off above 100) as a when on a string. Refactor it to a Strategy passed as a function type, then add a fourth rule without editing the old ones.