Solution - #4462
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation has two critical violations that must be fixed:
-
Missing
instanceof Herbivorecheck in thebitemethod - carnivores can currently bite other carnivores, which violates the task requirement. Addif (!(herb instanceof Herbivore)) return;at the start of the bite method. -
Violates checklist item #1 - you use
indexOf+spliceto remove dead animals, but the checklist explicitly requires usingAnimal.alive = Animal.alive.filter(animal => animal.health > 0);instead. -
Death condition issue - using
=== 0instead of<= 0means animals with health below 0 won't be removed from thealivearray.
Please fix these issues and resubmit.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| class Carnivore extends Animal { | ||
| // write your code here | ||
| bite(herb) { |
There was a problem hiding this comment.
This check doesn't verify if herb is an instance of Herbivore. According to the requirements, the bite method should only work on herbivores, not on other carnivores. Add a check for herb instanceof Herbivore.
| if (herb.health === 0) { | ||
| const i = Animal.alive.indexOf(herb); | ||
|
|
||
| Animal.alive.splice(i, 1); |
There was a problem hiding this comment.
This uses indexOf + splice which violates checklist item #1: 'Try to avoid nesting loops (indexOf + splice), use filter instead'. Use Animal.alive = Animal.alive.filter(animal => animal.health > 0); to remove dead animals.
| if (herb.hidden === false) { | ||
| herb.health -= 50; | ||
| } | ||
|
|
There was a problem hiding this comment.
Using === 0 instead of <= 0 means an animal with negative health (e.g., -50) won't be removed from Animal.alive.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The implementation correctly handles all requirements: Herbivore instances can hide to protect themselves, Carnivore instances can bite herbivores to reduce their health by 50 points, and dead animals (health ≤ 0) are properly removed from the static Animal.alive array using the filter method. The bite method appropriately checks both the instance type and hidden status before dealing damage, preventing carnivores from biting each other or hidden herbivores. All checklist items and task requirements have been satisfied. Great work on the iterative improvements!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.