We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Experience Points

Adventurers need experience points (XP) to level up and become stronger. We want to show the total XP a player has gained given their current level.

Each character starts with 0 XP at level 1. To reach the next level, they need to accumulate additional XP equal to their current level times 5.

For example:

  • At level 1, XP is 0.
  • To reach level 2, we need 5 XP (1 * 5) added to the current XP so far (0).
  • At level 2, XP is 5.
  • To reach level 3: we need 10 XP (2 * 5) added to the current XP so far (5).
  • At level 3, XP is 15.
  • To reach level 4: we need 15 XP (3 * 5) added to the current XP so far (15).
  • And so on...

To summarize the calculation in a table:

Level XP so far XP for next level
1 0 5
2 5 10
3 15 15
4 30 20

Assignment

Complete the calculate_experience_points function.

It accepts a level (integer) and returns the total XP a player has gained so far.