Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny-JS-World OOP #570

Merged
merged 1 commit into from
Oct 9, 2022
Merged
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
66 changes: 66 additions & 0 deletions submissions/nvklap/tinyoop/index.js
Original file line number Diff line number Diff line change
@@ -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()));