Skip to content

Commit 12709f1

Browse files
committed
Solution2
1 parent 35a50a7 commit 12709f1

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

src/herbivoresAndCarnivores.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ class Herbivore extends Animal {
2727

2828
class Carnivore extends Animal {
2929
bite(target) {
30-
if (target instanceof Carnivore) {
31-
return;
32-
}
33-
34-
if (target.hidden) {
35-
return;
36-
}
37-
38-
target.health -= 50;
30+
if (target instanceof Herbivore && !target.hidden) {
31+
target.health -= 50;
3932

40-
if (target.health <= 0) {
41-
target.die();
33+
if (target.health <= 0) {
34+
target.die();
35+
}
4236
}
4337
}
4438
}

0 commit comments

Comments
 (0)