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 ) {
7+ this . name = name ;
8+ this . health = 100 ;
9+ Animal . alive . push ( this ) ;
10+ }
11+
12+ checkAlive ( ) {
13+ if ( this . health <= 0 ) {
14+ const index = Animal . alive . indexOf ( this ) ;
15+
16+ if ( index !== - 1 ) {
17+ Animal . alive . splice ( index , 1 ) ;
18+ }
19+ }
20+ }
521}
622
723class Herbivore extends Animal {
8- // write your code here
24+ constructor ( name ) {
25+ super ( name ) ;
26+ this . hidden = false ;
27+ }
28+
29+ hide ( ) {
30+ this . hidden = true ;
31+ }
932}
1033
1134class Carnivore extends Animal {
12- // write your code here
35+ bite ( target ) {
36+ if ( ! ( target instanceof Herbivore ) ) {
37+ return ;
38+ }
39+
40+ if ( target . hidden ) {
41+ return ;
42+ }
43+
44+ target . health -= 50 ;
45+
46+ if ( target . health < 0 ) {
47+ target . health = 0 ;
48+ }
49+
50+ target . checkAlive ( ) ;
51+ }
1352}
1453
1554module . exports = {
You can’t perform that action at this time.
0 commit comments