Skip to content

Commit e8ec0dd

Browse files
committed
solution
1 parent ae59795 commit e8ec0dd

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/herbivoresAndCarnivores.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
'use strict';
22

33
class Animal {
4-
// write your code here
4+
static alive = [];
5+
constructor(name, health = 100) {
6+
this.name = name;
7+
this.health = health;
8+
Animal.alive.push(this);
9+
}
10+
static removeFromList() {
11+
Animal.alive = Animal.alive.filter((animal) => animal.health > 0);
12+
}
513
}
614

715
class Herbivore extends Animal {
8-
// write your code here
16+
constructor(name) {
17+
super(name);
18+
this.hidden = false;
19+
}
20+
hide() {
21+
this.hidden = true;
22+
}
923
}
1024

1125
class Carnivore extends Animal {
12-
// write your code here
26+
bite(animal) {
27+
if (!animal.hidden && animal instanceof Herbivore) {
28+
animal.health -= 50;
29+
Animal.removeFromList();
30+
}
31+
}
1332
}
1433

1534
module.exports = {

0 commit comments

Comments
 (0)