From 65cfff39deb637c3fceeaaa9969b36f6be2b262a Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 11 Oct 2022 11:57:11 +0200 Subject: [PATCH 1/2] a-tiny-JS-world-OOP style --- .../igarok88/a-tiny-JS-world-OOP/index.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 submissions/igarok88/a-tiny-JS-world-OOP/index.js diff --git a/submissions/igarok88/a-tiny-JS-world-OOP/index.js b/submissions/igarok88/a-tiny-JS-world-OOP/index.js new file mode 100644 index 0000000000..deff39f854 --- /dev/null +++ b/submissions/igarok88/a-tiny-JS-world-OOP/index.js @@ -0,0 +1,49 @@ +import { print } from "./js/lib.js"; +/* Refer to https://github.com/OleksiyRudenko/a-tiny-JS-world for the task details + + Code repository: https://github.com/igarok88/a-tiny-JS-world + Web app: https://igarok88.github.io/a-tiny-JS-world/ + */ + +class Inhabitants { + constructor(species, name, gender, legs, saying) { + this.species = species; + this.name = name; + this.gender = gender; + this.legs = legs; + this.saying = saying; + } + + getArrValues() { + return [this.species, this.name, this.gender, this.legs, this.saying]; + } +} + +class Human extends Inhabitants { + constructor(species, name, gender, legs, hands, saying) { + super(species, name, gender, legs, saying); + this.hands = hands; + } + + getArrValues() { + return [ + this.species, + this.name, + this.gender, + this.legs, + this.hands, + this.saying, + ]; + } +} + +const dog = new Inhabitants("dog", "Sharik", "male", 4, "woof-woof!"); +const cat = new Inhabitants("cat", "Mirzik", "male", 4, "meow-meow!"); +const woman = new Human("woman", "Yulia", "famele", 2, 2, "Hi Ihor!"); +const man = new Human("man", "Ihor", "male", 2, 2, "Hello Yulia!"); + +const inhabitants = [dog, cat, woman, man]; + +inhabitants.forEach((obj) => { + print(obj.getArrValues().join("; ")); +}); From efe4e02b6b9b6f42ebf38568fdd7bdb24dd5e37a Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 11 Oct 2022 13:14:33 +0200 Subject: [PATCH 2/2] change method name in class --- submissions/igarok88/a-tiny-JS-world-OOP/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/submissions/igarok88/a-tiny-JS-world-OOP/index.js b/submissions/igarok88/a-tiny-JS-world-OOP/index.js index deff39f854..674e54efb9 100644 --- a/submissions/igarok88/a-tiny-JS-world-OOP/index.js +++ b/submissions/igarok88/a-tiny-JS-world-OOP/index.js @@ -14,7 +14,7 @@ class Inhabitants { this.saying = saying; } - getArrValues() { + getInhabitantProps() { return [this.species, this.name, this.gender, this.legs, this.saying]; } } @@ -25,7 +25,7 @@ class Human extends Inhabitants { this.hands = hands; } - getArrValues() { + getInhabitantProps() { return [ this.species, this.name, @@ -45,5 +45,5 @@ const man = new Human("man", "Ihor", "male", 2, 2, "Hello Yulia!"); const inhabitants = [dog, cat, woman, man]; inhabitants.forEach((obj) => { - print(obj.getArrValues().join("; ")); + print(obj.getInhabitantProps().join("; ")); });