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 ) {
7+ this . name = name ;
8+ this . health = health || 100 ;
9+ Animal . alive . push ( this ) ;
10+ }
11+
12+ die ( ) {
13+ Animal . alive = Animal . alive . filter ( ( animal ) => animal !== this ) ;
14+ }
515}
616
717class Herbivore extends Animal {
8- // write your code here
18+ constructor ( name , health ) {
19+ super ( name , health ) ;
20+ this . hidden = false ;
21+ }
22+
23+ hide ( ) {
24+ this . hidden = true ;
25+ }
926}
1027
1128class Carnivore extends Animal {
12- // write your code here
29+ bite ( target ) {
30+ if ( target instanceof Carnivore ) {
31+ return ;
32+ }
33+
34+ if ( target . hidden ) {
35+ return ;
36+ }
37+
38+ target . health -= 50 ;
39+
40+ if ( target . health <= 0 ) {
41+ target . die ( ) ;
42+ }
43+ }
1344}
1445
1546module . exports = {
You can’t perform that action at this time.
0 commit comments