Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions .github/workflows/test.yml-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
33 changes: 30 additions & 3 deletions src/herbivoresAndCarnivores.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
'use strict';

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

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

die() {
Animal.alive = Animal.alive.filter((animal) => animal !== this);
}
}

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) {
if (!(target instanceof Herbivore) || target.hidden) {
return; // Cannot bite another carnivore or a hiding herbivore
}

target.health -= 50;

if (target.health <= 0) {
target.die();
}
}
}

module.exports = {
Expand Down
Loading