Skip to content

Commit aaeacd8

Browse files
committed
Solution
1 parent ae59795 commit aaeacd8

4 files changed

Lines changed: 50 additions & 8 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [20.x]
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- run: npm install
23+
- run: npm test

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"license": "GPL-3.0",
1818
"devDependencies": {
1919
"@mate-academy/eslint-config": "latest",
20-
"@mate-academy/scripts": "^1.8.6",
20+
"@mate-academy/scripts": "^2.1.3",
2121
"eslint": "^8.57.0",
2222
"eslint-plugin-jest": "^28.6.0",
2323
"eslint-plugin-node": "^11.1.0",

src/herbivoresAndCarnivores.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
'use strict';
22

33
class Animal {
4-
// write your code here
4+
static alive = [];
5+
constructor(name) {
6+
this.health = 100;
7+
this.name = name;
8+
Animal.alive.push(this);
9+
}
510
}
611

712
class Herbivore extends Animal {
8-
// write your code here
13+
hidden = false;
14+
hide() {
15+
this.hidden = true;
16+
}
917
}
1018

1119
class Carnivore extends Animal {
12-
// write your code here
20+
bite(target) {
21+
if (target instanceof Herbivore && !target.hidden) {
22+
target.health -= 50;
23+
}
24+
25+
if (target.health <= 0) {
26+
Animal.alive = Animal.alive.filter(
27+
(animal) => animal.name !== target.name,
28+
);
29+
}
30+
}
1331
}
1432

1533
module.exports = {

0 commit comments

Comments
 (0)