The Hero class allows you to create objects on this model :
{
name: string,
power: number,
life: number,
hit: function,
alive: function
}The hit method has a damage parameter and should reduce the number of life points of the Hero by as damage received.
The alive method should return true if the number of life points of the hero is greater than zero and false otherwise.
Create two instances of Hero and check that the hit and alive methods work.
Add the weapon attribute (of string type) to the Hero class without modifying the constructor (so weapon is not initialized).
Modify the hit method to add a second parameter, weapon.
Create three classes HeroAxe, HeroSword and HeroSpear which inherit from Hero.
These three classes call the constructor of their parent and initialize weapon with the values axe, sword or spear as appropriate.
In the HeroAxe, HeroSword and HeroSpear classes, override the hit method to take into account the following cases:
HeroAxe: if theweaponparameter is equal toword, multiplydamageby 2HeroSword: if theweaponparameter is equal tospear, multiplydamageby 2HeroSpear: if theweaponparameter is equal toaxis, multiplydamageby 2
Create instances of the three classes HeroAxe, HeroSword and HeroSpear and check that the hit methods work correctly.
Create a loop that makes two instances of Hero subclasses fight each other (they attack at the same time).
When at least one of them is dead, log {heroName} wins. If both of them are dead, log It's a draw.