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

OOP exercise #93

Merged
merged 9 commits into from
Aug 28, 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
67 changes: 67 additions & 0 deletions submissions/asaMitaka/OOP/indexClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Inhabitants {
constructor(species, name, gender, saying) {
this.species = species;
this.name = name;
this.gender = gender;
this.saying = saying;
}

tellAboutClass() {
return `${this.saying} My name is ${this.name} I am ${this.species} ${this.gender}.`;
}
}

class Animal extends Inhabitants{
constructor(species, name, gender, saying) {
super(species, name, gender, saying);
this.legs = 4;
}

tellAboutClass() {
return super.tellAboutClass() + `I have ${this.legs} legs`;
}
}

class Cat extends Animal {
constructor(name, gender, saying) {
super('cat', name, gender, saying);
}
}

class Dog extends Animal {
constructor(name, gender, saying) {
super('dog', name, gender, saying);
}
}

class Human extends Inhabitants{
constructor(name, gender, saying) {
super('human', name, gender, saying);
this.hands = 2;
this.legs = 2;
}

tellAboutClass() {
return super.tellAboutClass() + `I have ${this.hands} hands and ${this.legs} legs`;
}
}

class Man extends Human {
constructor(name, saying) {
super(name, 'male', saying);
}
}

class Woman extends Human {
constructor(name, saying) {
super(name, 'female', saying);
}
}

const john = new Man('John', 'Hi');
const mary = new Woman('Mary', 'Hello');
const boris = new Dog('Boris', 'male', 'Woof');
const sam = new Cat('Sam', 'female', 'Meoow');

const inhabitants = [john, mary, boris, sam];
inhabitants.forEach( item => print(item.tellAboutClass()));