Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/herbivoresAndCarnivores.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
'use strict';

class Animal {
// write your code here
static alive = [];

constructor(name, health = 100) {
this.name = name;
this.health = health;
Animal.alive.push(this);
}

die() {
Animal.alive = Animal.alive.filter((animal) => animal !== this);
}
}

class Herbivore extends Animal {
// write your code here
hidden = false;

hide() {
this.hidden = true;
}
}

class Carnivore extends Animal {
// write your code here
bite(target) {
if (target instanceof Carnivore || target.hidden) {
return;
}
target.health -= 50;

if (target.health <= 0) {
target.die();
}
}
}

module.exports = {
Expand Down
Loading