Skip to content

Commit 440a946

Browse files
committed
Deploy animals
1 parent ae59795 commit 440a946

4 files changed

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

3+
'use strict';
4+
35
class Animal {
4-
// write your code here
6+
static alive = [];
7+
8+
constructor(name) {
9+
this.health = 100;
10+
this.name = name;
11+
12+
Animal.alive.push(this);
13+
}
14+
15+
die() {
16+
Animal.alive = Animal.alive.filter((animal) => animal !== this);
17+
}
518
}
619

720
class Herbivore extends Animal {
8-
// write your code here
21+
constructor(name) {
22+
super(name);
23+
24+
this.hidden = false;
25+
}
26+
27+
hide() {
28+
this.hidden = true;
29+
}
930
}
1031

1132
class Carnivore extends Animal {
12-
// write your code here
33+
bite(animal) {
34+
if (animal instanceof Herbivore && animal.hidden === false) {
35+
animal.health -= 50;
36+
37+
if (animal.health <= 0) {
38+
animal.die();
39+
}
40+
}
41+
}
1342
}
1443

1544
module.exports = {

0 commit comments

Comments
 (0)