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