There was an error while loading. Please reload this page.
1 parent ae59795 commit e8ec0ddCopy full SHA for e8ec0dd
1 file changed
src/herbivoresAndCarnivores.js
@@ -1,15 +1,34 @@
1
'use strict';
2
3
class Animal {
4
- // write your code here
+ 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
13
}
14
15
class Herbivore extends Animal {
16
+ constructor(name) {
17
+ super(name);
18
+ this.hidden = false;
19
20
+ hide() {
21
+ this.hidden = true;
22
23
24
25
class Carnivore extends Animal {
26
+ bite(animal) {
27
+ if (!animal.hidden && animal instanceof Herbivore) {
28
+ animal.health -= 50;
29
+ Animal.removeFromList();
30
31
32
33
34
module.exports = {
0 commit comments