File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33class Animal {
44 // write your code here
5+ static alive = [ ] ;
6+ constructor ( name , hidden = false ) {
7+ this . name = name ;
8+ this . health = 100 ;
9+ this . hidden = hidden ;
10+
11+ Animal . alive . push ( this ) ;
12+ }
13+
14+ static getAliveList ( ) {
15+ return Animal . alive . map ( ( animal ) => {
16+ if ( animal instanceof Herbivore ) {
17+ return {
18+ name : animal . name ,
19+ health : animal . health ,
20+ hidden : animal . hidden ,
21+ } ;
22+ } else {
23+ return { name : animal . name , health : animal . health } ;
24+ }
25+ } ) ;
26+ }
527}
628
729class Herbivore extends Animal {
30+ constructor ( name , hidden = false ) {
31+ super ( name , hidden ) ;
32+ }
833 // write your code here
34+ hide ( ) {
35+ this . hidden = true ;
36+ }
937}
1038
1139class Carnivore extends Animal {
40+ // No custom constructor needed as it only calls the parent constructor
1241 // write your code here
42+ bite ( target ) {
43+ if ( target instanceof Herbivore && ! target . hidden ) {
44+ target . health -= 50 ;
45+
46+ if ( target . health <= 0 ) {
47+ Animal . alive = Animal . alive . filter ( ( animal ) => animal !== target ) ;
48+ }
49+ }
50+ }
1351}
1452
1553module . exports = {
You can’t perform that action at this time.
0 commit comments