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