Created
February 15, 2023 21:10
-
-
Save liammccon/55e4577bf48296fe7a7bf8e03542e59e to your computer and use it in GitHub Desktop.
My code for the All Star Code JavaScript Assessment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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