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+ }
511}
612
713class Herbivore extends Animal {
8- // write your code here
14+ constructor ( name ) {
15+ super ( name ) ;
16+ this . hidden = false ;
17+ }
18+
19+ hide ( ) {
20+ this . hidden = true ;
21+ }
922}
1023
1124class Carnivore extends Animal {
12- // write your code here
25+ bite ( animal ) {
26+ if ( animal . hidden === false ) {
27+ animal . health -= 50 ;
28+
29+ if ( animal . health <= 0 ) {
30+ Animal . alive = Animal . alive . filter (
31+ ( animalToCheck ) => animalToCheck !== animal ,
32+ ) ;
33+ }
34+ }
35+ }
1336}
1437
38+ const tiger = new Carnivore ( 'Tiger' ) ;
39+ const zebra = new Herbivore ( 'Zebra' ) ;
40+
41+ tiger . bite ( zebra ) ;
42+ tiger . bite ( zebra ) ;
43+
44+ console . log ( Animal . alive ) ;
45+
46+ // console.log(Animal.alive());
47+
1548module . exports = {
1649 Animal,
1750 Herbivore,
You can’t perform that action at this time.
0 commit comments