47.1 - Battle Scene: Damage, Practice (JS lessons โ arguments and return)
๐ Task: Battle HP Bar
The page shows a character with an HP bar above it. Below the character are
4 attack buttons.
๐๏ธ What you need to prepare in HTML:
- An element with the HP text โ for example,
class="hp-text"
- The HP bar โ for example,
class="hp-bar-fill"
- 4 attack buttons
โ๏ธ Battle rules:
- โค๏ธ Max HP โ 100, the same at the start of the battle
- ๐ Punch โ 10 damage
- ๐ฆต Kick โ 15 damage
- ๐ฅ Fireball โ 25 damage
- ๐ฅ Critical โ 40 damage
๐ How this should work:
Clicking any of the 4 buttons decreases the character's current HP by that
button's damage. HP can't go below 0. After every click the HP bar and
text on screen update and show the current value.
๐งช Example:
The character starts the battle with 100 HP. The user clicks the buttons in order:
- ๐ฅ Fireball โ 100 - 25 = 75
- ๐ Punch โ 75 - 10 = 65
- ๐ฅ Critical โ 65 - 40 = 25
After these three clicks the screen should show:
25 / 100 HP