Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions src/herbivoresAndCarnivores.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
'use strict';

class Animal {
// write your code here
static alive = [];

constructor(name) {
this.name = name;
this.health = 100;
Animal.alive.push(this);
}

die() {
// Usar filter para manter apenas os animais com saúde maior que 0
// eslint-disable-next-line prettier/prettier

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you should not leave comments on the project. Also, you should work your code to satisfy eslint rules, never disable eslint.

Animal.alive = Animal.alive.filter((animal) => animal.health > 0);
}
}

class Herbivore extends Animal {
// write your code here
constructor(name) {
super(name);
this.hidden = false;
}

hide() {
this.hidden = true;
}
}

class Carnivore extends Animal {
// write your code here
bite(target) {
// Verifica apenas se o alvo é um Herbivore e não está escondido
if (target instanceof Herbivore && !target.hidden) {
target.health -= 50;

// Se a saúde for menor ou igual a 0, o alvo morre
if (target.health <= 0) {
target.die();
}
}
}
}

module.exports = {
Expand Down