The full text of this chapter, to read or revisit. To practise, do the exercises.
Exercise 1 — Codémon Stats Generator
A wild Pyrochu appears! Time to scan its stats.
Generate Pyrochu's stats:
1.
hp
is
100
2.
attack
is
45
3. Display both in the console
Starter code
// Generate Pyrochu's stats
Exercise 2 — Battle Damage Calculator
You decide to catch Pyrochu! Time for battle.
Calculate the damage:
1. Take Pyrochu's
attack
2. Multiply it by the
bonus
3. Round the result to a whole number
4. Display the total damage
Starter code
let hp = 100;
let attack = 45;
let bonus = 1.25;
Exercise 3 — Codémon Battle Simulator
Success! You caught Pyrochu 🎉
But wait... A wild Florachu appears and challenges you!
Who will win?
1. Pyrochu has
100
HP
2. Give Florachu a random whole HP between 80 and 120
3. Find the highest HP of the two
4. Display both HP and the winner's HP
Starter code
let pyrochuHP = 100;