File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict' ;
22
33class Animal {
4- // write your code here
4+ static alive = [ ] ;
5+
6+ constructor ( name , health = 100 ) {
7+ this . name = name ;
8+ this . health = health ;
9+
10+ Animal . alive . push ( this ) ;
11+ }
512}
613
714class Herbivore extends Animal {
8- // write your code here
15+ constructor ( name , health = 100 ) {
16+ super ( name , health ) ;
17+
18+ this . hidden = false ;
19+ }
20+
21+ hide ( ) {
22+ this . hidden = true ;
23+ }
924}
1025
1126class Carnivore extends Animal {
12- // write your code here
27+ constructor ( name , health = 100 ) {
28+ super ( name , health ) ;
29+ }
30+
31+ bite ( herbivore ) {
32+ if ( ! ( herbivore instanceof Herbivore ) || herbivore . hidden ) {
33+ return ;
34+ }
35+
36+ herbivore . health -= 50 ;
37+
38+ if ( herbivore . health <= 0 ) {
39+ Animal . alive = Animal . alive . filter ( ( animal ) => animal !== herbivore ) ;
40+ }
41+ }
1342}
1443
1544module . exports = {
You can’t perform that action at this time.
0 commit comments