Question

Define the Pokemon class using the given specifications in JavaScript(ES6) Pokemon class specifications The Pokemon class...

Define the Pokemon class using the given specifications in JavaScript(ES6)

Pokemon class specifications

  1. The Pokemon class should be defined.
  2. A Pokemon object should be initialized, or constructed, by passing in 5 arguments, which should correspond to the following 5 properties in order: .name, .attack, .defense, .health, and .type.
    • For example:
     const charmander = new Pokemon("charmander", 12, 8, 30, "fire");
     console.log(charmander.name);    // charmander
     console.log(charmander.attack);  // 12
     console.log(charmander.defense); // 8
     console.log(charmander.health);  // 30
     console.log(charmander.type);    // fire
    • Data type validation is not needed here. You can assume the following property:type pairings will always be used:
      • .name:string
      • .attack:number
      • .defense:number
      • .health:number
      • .type:string
  3. Pokemon objects should have a takeDamage() method, which takes a number as an argument and properly reduces the .health of the Pokemon by that number.
    • Note: if the .health would go below 0, the .health should be set to 0 instead.
    • For example:
     console.log(charmander.health);  // 30
     
     charmander.takeDamage(5);
     console.log(charmander.health);  // 25
    
     charmander.takeDamage(2000);
     console.log(charmander.health);  // 0
  4. Pokemon objects should have an attackOpponent() method, which takes a Pokemon object as an argument (the opponent being attacked). This method should call the takeDamage() method belonging to the opposing Pokemon and provide the appropriate damage as an argument. Damage is calculated simply: DAMAGE = CURRENT_POKEMON_ATTACK - OPPONENT_POKEMON_DEFENSE.
    • For example:
     const charmander = new Pokemon("charmander", 12, 8, 30, "fire");
     const bulbasaur = new Pokemon("bulbasaur", 7, 9, 35, "grass/poison");
    
     console.log(charmander.attack);  // 12
     console.log(bulbasaur.defense);  // 9
     // 12 attack - 9 defense = 3 damage
    
     console.log(bulbasaur.health);  // 35
     charmander.attackOpponent(bulbasaur);   // charmander attacks bulbasaur
     console.log(bulbasaur.health);  // 32
    • By default, attacking a Pokemon should do at the very least 1 damage. Consider what might happen if the Pokemonbeing attacked has a higher .defense than the .attack of the attacking Pokemon.
  5. Pokemon objects should have a display() method, which takes no arguments and returns a string with the current pokemon's .name in all caps, .type in all caps and in parenthesis, and .health with a forward-slash, "/", followed by the .health the Pokemon was initialized with.
    • For example:
     const pikachu = new Pokemon("pikachu", 9, 10, 25, "electric");
     pikachu.display(); // "PIKACHU (ELECTRIC) 25/25"
    
     pikachu.health = 12;
     pikachu.display(); // "PIKACHU (ELECTRIC) 12/25"
0 0
Add a comment Improve this question Transcribed image text
Answer #1

java.script code for class pokemon:

<script>
class Pokemon {

constructor(name,attack,defense,health,type) {
this.name = name;
this.attack = attack;
this.defense = defense;
this.health = health;
this.ihealth = health;
this.type = type;
}
takeDamage(num){
this.health = (this.health) - num;
if(this.health < 0)
this.health = 0;
}
attackOpponent(opponent){
var damage = this.attack - opponent.defense;
if(damage < 0){
damage = 1;
}
opponent.health = opponent.health - damage;
}
display(){
console.log((this.name).toUpperCase()+" ("+(this.type).toUpperCase()+") "+this.health+"/"+this.ihealth);
}
}

const pikachu = new Pokemon("pikachu", 9, 10, 25, "electric");
pikachu.display(); // "PIKACHU (ELECTRIC) 25/25"

pikachu.health = 12;
pikachu.display(); // "PIKACHU (ELECTRIC) 12/25"
</script>

Add a comment
Know the answer?
Add Answer to:
Define the Pokemon class using the given specifications in JavaScript(ES6) Pokemon class specifications The Pokemon class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Instructions Project 2: Gotta Catch ‘Em All Due: July 16 by Midnight For this...

    In C++ Instructions Project 2: Gotta Catch ‘Em All Due: July 16 by Midnight For this project you will be designing and implementing a system, in C++, to catalogue Pokémon, their trainers, and the local Pokémon gyms. Your system should act as a database and allow the user to load in multiple tables of data, run basic queries on the data, and then store the data off for later use. Additionally, sample input files will not be uploaded to Canvas,...

  • C++ 15.15 Lab: Abstract base class Base Class The base Character class is located Character.h and...

    C++ 15.15 Lab: Abstract base class Base Class The base Character class is located Character.h and cannot be changed. enum HeroType {WARRIOR, ELF, WIZARD}; const double MAX_HEALTH = 100.0; class Character { protected:    HeroType type;    string name;    double health;    double attackStrength; public:     Character(HeroType type, const string &name, double health, double attackStrength);     HeroType getType() const;     const string & getName() const;     /* Returns the whole number of the health value (static_cast to int). */     int getHealth() const;     void setHealth(double h);     /* Reduces...

  • Base Class enum HeroType {WARRIOR, ELF, WIZARD}; const double MAX_HEALTH = 100.0; class Character { protected:...

    Base Class enum HeroType {WARRIOR, ELF, WIZARD}; const double MAX_HEALTH = 100.0; class Character { protected: HeroType type; string name; double health; double attackStrength; public: Character(HeroType type, const string &name, double health, double attackStrength); HeroType getType() const; const string & getName() const; /* Returns the whole number of the health value (static_cast to int). */ int getHealth() const; void setHealth(double h); /* Returns true if getHealth() returns an integer greater than 0, otherwise false */ bool isAlive() const; virtual void...

  • using C++ Requirements: . Classes you must create o Monster must be an abstract class Each monster has . an attack) o randomly generate a number between 0 and strength for each attack (Strength 10 wo...

    using C++ Requirements: . Classes you must create o Monster must be an abstract class Each monster has . an attack) o randomly generate a number between 0 and strength for each attack (Strength 10 would generate 0-10) add up all the damage done return total damage o o e a number of attacks . a number for strength used during attacking . a string representing the type » accessor for type o Goblin inherits from Monster type is "Goblin"...

  • Question 2 : Virus Wars A popular subgenre of strategy game is the so-called Virus War...

    Question 2 : Virus Wars A popular subgenre of strategy game is the so-called Virus War format, where the player is shown a field of cells, each with a virus count, and may attack other cells within a certain range. We are going to write some classes in Python to implement a simple Virus Wars game. 2a) The position class (9 points) Everything within this game is going to require a position, so it makes sense to define it up...

  • (a) FileIO In the FileIO class add a public static method named writeCharacter. This method takes...

    (a) FileIO In the FileIO class add a public static method named writeCharacter. This method takes as input a Character to write, and a String which is the filename to write to. Within this writeCharacter method, use the FileWriter and BufferedWriter objects to write the character’s information back to a file. Make sure to catch the IOException when writing a file, and throw an IllegalArgumentException with an appropriate error message. If you prefer, you can also use the throws statement...

  • Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count...

    Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count of all monsters instantiated and includes a static method that generates a new random monster object. In software engineering, a method that generates new instances of classes based on configuration information is called the Factory pattern. UML Class Diagram: Monster - name: String - health: int - strength: int - xp: int + spawn(type:String): Monster + constructor (name: String, health: int, strength: int, xp:...

  • HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh...

    HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh DESCRIPTION Objectives To write a classes based on sets of specifications To write a main class to be used in a multi-class Java program To use inheritance to extend a class (optional, EC) To override methods in subclasses (optional, EC) Groups You may work with a partner on this assignment. A header comment (In every Java file) should include authors (group members) and collaborators...

  • True/False 1. Browser-based validation can replace the need to write custom JavaScript code to validate user...

    True/False 1. Browser-based validation can replace the need to write custom JavaScript code to validate user input. 2. When you add a new property to an object that has been instantiated from a constructor function, the new property is available to all objects instantiated from the same constructor function. 3. Because objects in the browser object model are actually part of the web browser, you do not need to instantiate them in order to use them in your programs. 4....

  • C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class...

    C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class called Player that represents a player in the National Hockey League. Player class Use the following class definition: class Player { public: Player(); Player( const char [], int, int, int ); void printPlayer(); void setName( const char [] ); void setNumber( int ); void changeGoals( int ); void changeAssists( int ); int getNumber(); int getGoals(); int getAssists(); private: char name[50]; int number; int goals;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT