diff --git a/src/herbivoresAndCarnivores.js b/src/herbivoresAndCarnivores.js index 637b47ba4..effcca102 100644 --- a/src/herbivoresAndCarnivores.js +++ b/src/herbivoresAndCarnivores.js @@ -1,15 +1,39 @@ 'use strict'; class Animal { - // write your code here + static alive = []; + + constructor(name) { + this.name = name; + this.health = 100; + Animal.alive.push(this); + } + + checkHealth() { + if (this.health <= 0) { + Animal.alive = Animal.alive.filter((animal) => animal !== this); + } + } } class Herbivore extends Animal { - // write your code here + constructor(name) { + super(name); + this.hidden = false; + } + + hide() { + this.hidden = true; + } } class Carnivore extends Animal { - // write your code here + bite(target) { + if (target instanceof Herbivore && !target.hidden) { + target.health -= 50; + target.checkHealth(); + } + } } module.exports = {