Reference no: EM133860433
Question
JavaScript SuperHero and SuperVillain classes
In this lab, you will create two JavaScript classes so a super hero and villain can battle, as shown below.
The given index.html file contains two drop-down widgets listing the names of super heroes and super villains. A paragraph with ID winner is empty but will display the winner of a battle between the selected hero and villain.
Investigate the given JavaScript
The given hero.js script contains the following:
A SuperHuman class with properties name and powerLevel.
Two constants, heroes and villains, that contain a list of SuperHero and SuperVillain objects.
A registerHandlers() function registers change event handlers for the two drop-down widgets and does not need to be altered.
A selectionChanged() function that is called when a hero or villain is selected. selectionChanged() is only partially implemented.
Make modifications
Make the following modifications:
Create SuperHero and SuperVillain classes that extend the SuperHuman class. Both classes should have a constructor that has name, alias, and powerLevel parameters, and the constructor should call the parent class' constructor with the given name and powerLevel.
Add a battle() method to the SuperHero class that has a SuperVillain parameter. battle() should return true if the hero's powerLevel is >= the villain's powerLevel, false otherwise.
Add an getEvilChuckle() method to the SuperVillain class that returns the string "Ha ha ha!".
Modify selectionChanged() to call the selected hero's battle() method, passing in the selected villain. Display the battle winner's alias in the winner paragraph.
When the modifications are complete, the web page will show the winner between the selected hero and villain.