

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to Object-Oriented Programming
incomplete
2: Clean Code
incomplete
3: DRY Code
incomplete
4: DRY Review
incomplete
This lesson's interactive features are locked, please to keep using them
Another "rule of thumb" for writing maintainable code is "Don't Repeat Yourself" (DRY). It means that, when possible, you should avoid writing the same code in multiple places. Repeating code can be bad because:
Your manager noticed that "Age of Dragons" has a lot of repetitive code. She's asked you to update the fight_soldiers function so that the DPS (damage-per-second) calculation logic is only written in one place.
Notice how these two lines are practically identical:
soldier_one_dps = soldier_one["damage"] * soldier_one["attacks_per_second"]
soldier_two_dps = soldier_two["damage"] * soldier_two["attacks_per_second"]
The soldier with the greater DPS will win the fight!