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

Task TJW OOP #580

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
63 changes: 63 additions & 0 deletions submissions/Mifaresss/tiny-js-world-oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class Inhabitants {
constructor(name, species, gender, saying) {
this.name = name;
this.species = species;
this.gender = gender;
this.saying = saying;
}
prepareforPrinting() {
return `${this.name}; ${this.species}; ${this.gender}; ${this.saying};`
Mifaresss marked this conversation as resolved.
Show resolved Hide resolved
}
}

class Humans extends Inhabitants {
constructor(name, gender, saying) {
super(name, 'human', gender, saying);
this.legs = 2;
this.hands = 2;
}
prepareforPrinting() {
return `${super.prepareforPrinting()} ${this.legs}; ${this.hands}`;
Mifaresss marked this conversation as resolved.
Show resolved Hide resolved
}
}

class Animals extends Inhabitants {
constructor(name, species, gender, saying) {
super(name, species, gender, saying);
this.legs = 4;
Mifaresss marked this conversation as resolved.
Show resolved Hide resolved
}
prepareforPrinting() {
return `${super.prepareforPrinting()} ${this.legs}`;
}
}

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

const AlexMan = new Humans('Alex', 'male', 'Call me Thirteenth!');
const JohnMan = new Humans('John', 'male', 'My name is John');
const HarryMan = new Humans('Harry', 'male', 'Where is my magic wand?');

const AliceWomen = new Humans('Alice', 'female', 'I have special DNA');
const EmmaWomen = new Humans('Emma', 'female', 'Who is there?');
const StacyWomen = new Humans('Stacy', 'female', 'Hi!');

const BaxterDog = new Dog('Baxter', 'male', 'Woof-woof!');
const ArniDog = new Dog('Arni', 'male', 'Woof-woof!');

const LunyaCat = new Cat('Lunya', 'female', 'Meeooow!');
const TaychikCat = new Cat('Taychik', 'male', 'Meeooow!');


const inhabitants = [AlexMan, JohnMan, HarryMan, AliceWomen, EmmaWomen, StacyWomen, BaxterDog, ArniDog, LunyaCat, TaychikCat];
inhabitants.forEach(inhabitant => {
print(inhabitant.prepareforPrinting());
});