Question: Need a program in js to comeplete this prgram Create a prototype Pokemon object Using that prototype Pokemon object, create two pokemon (Pikachu, Butterfree). After
Need a program in js to comeplete this prgram
-
Create a prototype Pokemon object
-
Using that prototype Pokemon object, create two pokemon (Pikachu, Butterfree).
-
After creating two Pokemon, start the battle!
-
In your battle, write the logic to have the Pokemon alternate attacking each other
-
After each attack, output the results of the attack. The results should display the updated HP of each pokemon.
-
If at any point, a Pokemons HP goes to 0, end the battle and show a results message. The message show
-
BATTLE OVER! Header
-
The name of the Pokemon who won
-
The HP of the both Pokemon
-
When performing the battle, you must use the prototypes class functions.
Sample output of your program:
BATTLE START!
Pikachu (20HP) vs. Butterfree (30HP)
Pikachu attacks!
Butterfree takes 5 damage!
Pikachu: 20/20 HP
Butterfree: 25/30 HP
Butterfree attacks!
Pikachu takes 3 damage!
Pikachu: 17/30 HP
Butterfree: 25/30 HP
Pikachu attacks!
Butterfree takes 5 damage!
Pikachu: 17/20 HP
Butterfree: 20/30 HP
. (etc, etc, etc)
Butterfree attacks!
Butterfree misses!
Pikachu: 7/20 HP
Butterfree: 5/30 HP
.
Pikachu attacks!
Butterfree takes 5 damage!
Butterfree fainted!
BATTLE OVER!
Pikachu wins!
Pikachu: 7/20 HP
Butterfree: 0/30 HP
Pokemon Prototype Object
The Pokemon prototype object has the following properties and functions:
Properties:
| Property | Description |
| name | The name of the Pokmeon (Pikachu, Butterfree, Charizard, etc) |
| maxHP | A number representing the maximum health points the Pokemon has. |
| currHP | A number representing the current amount of health points the Pokemon has. Initially, the currentHP equals maxHP. Whenever the pokemon takes damage, the amount of damage is deducted from the current HP. |
| attackPower | A number representing the amount of damage the Pokemon can do |
| isDead | True if the Pokemons current HP <= 0. False otherwise. |
Functions
| Function | Description |
| attack | This function determines if the Pokemons attempt to attack is succeeds or misses. There is a 35% chance that the attack will miss. If the attack misses, the other Pokemon takes 0 damage. If the attack is successful, return true. If the attack misses, return false. |
| takeDamage(amt) | This function reduces the amount of current HP the Pokemon has by the amount specified in the function parameter. For example, suppose a Pokemon has a current HP of 100. After calling takeDamage(25), the Pokemons current HP will be reduced to 75. If the current HP <= 0, then update the isDead property. |
| displayStats() | Outputs the pokemon name and current hp to the console. Example: Pikachu: 15/20 HP |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
