There was an error while loading. Please reload this page.
1 parent ae59795 commit 79188f9Copy full SHA for 79188f9
1 file changed
src/herbivoresAndCarnivores.js
@@ -1,15 +1,36 @@
1
'use strict';
2
3
class Animal {
4
- // write your code here
+ static alive = [];
5
+
6
+ constructor(name, health = 100) {
7
+ this.name = name;
8
+ this.health = health;
9
10
+ if (health > 0) {
11
+ Animal.alive.push(this);
12
+ }
13
14
}
15
16
class Herbivore extends Animal {
17
+ hidden = false;
18
19
+ hide() {
20
+ this.hidden = true;
21
22
23
24
class Carnivore extends Animal {
25
+ bite(animal) {
26
+ if (animal instanceof Herbivore && !animal.hidden && animal.health > 0) {
27
+ animal.health -= 50;
28
29
+ if (animal.health <= 0) {
30
+ Animal.alive = Animal.alive.filter((item) => item.health > 0);
31
32
33
34
35
36
module.exports = {
0 commit comments