Skip to content

Commit da049a9

Browse files
committed
Solution
1 parent ae59795 commit da049a9

4 files changed

Lines changed: 49 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: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
'use strict';
22

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

714
class Herbivore extends Animal {
8-
// write your code here
15+
hide() {
16+
this.hidden = true;
17+
}
918
}
1019

1120
class Carnivore extends Animal {
12-
// write your code here
21+
bite(target) {
22+
if (target instanceof Herbivore && !target.hidden) {
23+
target.health -= 50;
24+
}
25+
26+
if (target.health <= 0) {
27+
Animal.alive.splice(Animal.alive.indexOf(target), 1);
28+
}
29+
}
1330
}
1431

1532
module.exports = {

0 commit comments

Comments
 (0)