Skip to content

Instantly share code, notes, and snippets.

@liammccon
Created February 15, 2023 21:10
Show Gist options
  • Save liammccon/55e4577bf48296fe7a7bf8e03542e59e to your computer and use it in GitHub Desktop.
Save liammccon/55e4577bf48296fe7a7bf8e03542e59e to your computer and use it in GitHub Desktop.
My code for the All Star Code JavaScript Assessment
class Pokemon {
constructor(name, attack, defense, health, type ) {
this.name = name;
this.attack = attack;
this.defense = defense;
this.health = health;
this.type = type;
this.initialHealth = health;
}
takeDamage(damage){
this.health = this.health - damage;
if (this.health < 0) this.health = 0;
}
attackOpponent(opponent) {
const damage = this.attack - opponent.defense;
if (damage > 0){
opponent.takeDamage(damage);
}
//Otherwise do nothing because opponent's defense > this pokemon's attack
}
display(){
return `${this.name.toUpperCase()} (${this.type.toUpperCase()}) ${this.health}/${this.initialHealth}`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment