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