There was an error while loading. Please reload this page.
1 parent ae59795 commit 6ff78d3Copy full SHA for 6ff78d3
1 file changed
src/herbivoresAndCarnivores.js
@@ -1,15 +1,37 @@
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
+ Animal.alive.push(this);
11
+ }
12
}
13
14
class Herbivore extends Animal {
15
+ constructor(name, health) {
16
+ super(name, health);
17
+ this.hidden = false;
18
19
20
+ hide() {
21
+ this.hidden = true;
22
23
24
25
class Carnivore extends Animal {
26
+ bite(pray) {
27
+ if (pray instanceof Herbivore && !pray.hidden) {
28
+ pray.health -= 50;
29
30
31
+ if (pray.health <= 0) {
32
+ Animal.alive = Animal.alive.filter((animal) => animal !== pray);
33
34
35
36
37
module.exports = {
0 commit comments