From 44e34d11541b33af14819f2edd724ede419360d2 Mon Sep 17 00:00:00 2001 From: Nataliia Klapchuk Date: Wed, 14 Sep 2022 21:43:44 +0300 Subject: [PATCH] Initial commit --- submissions/nvklap/tinyoop/index.js | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 submissions/nvklap/tinyoop/index.js diff --git a/submissions/nvklap/tinyoop/index.js b/submissions/nvklap/tinyoop/index.js new file mode 100644 index 0000000000..2546ef639f --- /dev/null +++ b/submissions/nvklap/tinyoop/index.js @@ -0,0 +1,66 @@ +/* Refer to https://github.com/OleksiyRudenko/a-tiny-JS-world for the task details + Complete the below for code reviewers' convenience: + + Code repository: _put repo URL here_ + Web app: _put project's github pages URL here_ + */ + +// ======== OBJECTS DEFINITIONS ======== +class Inhabitant { + constructor(species, name, gender, saying, legs) { + this.species = species; + this.name = name; + this.gender = gender; + this.saying = saying; + this.legs = legs; + } + + getProperties() { + return ['species', 'name', 'gender', 'saying', 'legs'] + .map((property) => this[property]) + .join('; '); + } +} + +class Human extends Inhabitant { + constructor(gender, name, saying, legs = 2) { + super('human', name, gender, saying, legs); + this.hands = 2; + } + getProperties() { + return `${super.getProperties()}; ${this.hands}`; + } +} + +class Woman extends Human { + constructor(name, saying) { + super('female', name, saying); + } +} + +class Man extends Human { + constructor(name, saying) { + super('male', name, saying); + } +} + +class Dog extends Inhabitant { + constructor(name, gender, legs = 4) { + super('dog', name, gender, 'Woof!', legs); + } +} + +class Cat extends Inhabitant { + constructor(name, gender, legs = 4) { + super('cat', name, gender, 'Meow!', legs); + } +} + +// // ======== OUTPUT ======== +const dog = new Dog('Hugo', 'male'); +const cat = new Cat('Kitsya', 'female'); +const man = new Man('George', '...Hm'); +const woman = new Woman('Dorothy', 'Well...'); + +const inhabitants = [dog, cat, man, woman]; +inhabitants.forEach((inhabitant) => print(inhabitant.getProperties()));