Skip to content

Solution - #3926

Closed
jorgincode wants to merge 2 commits into
mate-academy:masterfrom
jorgincode:develop
Closed

jorgincode wants to merge 2 commits into
mate-academy:masterfrom
jorgincode:develop

Conversation

@jorgincode

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job on the overall structure of your classes! The use of inheritance and static properties is well-implemented and follows the requirements closely.

I'm requesting changes because there's one critical logic error that prevents the simulation from running as described in the task.

Required Change

Incorrect Death Condition

In src/herbivoresAndCarnivores.js, the bite method checks if an animal should die using the wrong condition.

  • The Issue: You are checking if (target.health <= 50).
  • The Requirement: An animal should only die when its health is less than or equal to 0.
  • The Impact: This bug causes a herbivore to be removed from the simulation immediately after the first bite, which is incorrect. It should survive one bite (health drops to 50) and only die after the second bite (health drops to 0).

To fix this, please update the condition to check if the target's health is at or below zero before calling target.die().

Suggestion for Improvement

I also noticed a small opportunity to make your code more concise. In the bite method, you have two separate guard clauses. These can be combined into a single if statement:

// You can combine these two checks:
if (!(target instanceof Herbivore)) {
  return;
}
if (target.hidden) {
  return;
}

// Into a single, more concise check:
if (!(target instanceof Herbivore) || target.hidden) {
  return;
}

This is just a suggestion for readability and isn't required to be changed. The main thing is to fix the death condition.

Once that's corrected, your solution will be perfect. Keep up the great work!


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/herbivoresAndCarnivores.js Outdated
Comment on lines +33 to +39
if (!(target instanceof Herbivore)) {
return;
}

if (target.hidden) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two guard clauses can be combined into a single if statement for better readability and conciseness:

if (!(target instanceof Herbivore) || target.hidden) {
  return;
}

Comment thread src/herbivoresAndCarnivores.js Outdated
Comment on lines +43 to +45
if (target.health <= 50) {
target.die();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the task description, an animal should die only when its health is less than or equal to 0. With the current condition target.health <= 50, a herbivore dies immediately after the first bite, which contradicts the behavior shown in the example.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this submission! Your implementation correctly meets all the requirements for the task.

The class structure using Animal, Herbivore, and Carnivore is well-designed and demonstrates a clear understanding of inheritance in JavaScript. The use of a static property Animal.alive to track all instances was implemented perfectly, and the logic within your methods is clean and efficient.

This is a model solution. Keep up the fantastic work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

@jorgincode jorgincode closed this by deleting the head repository Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants