Skip to content

Commit

Permalink
Oop classes (#436)
Browse files Browse the repository at this point in the history
* Add popup  files

* Add changes to style  files after review

* Changes style files

* Add changes in  pretti
er formatting and  changes  font-size to rem

* Fix focus  on  checkbox

* Fix  popup height

* Add  classes for inhabitants

* Fix  after review

* Set toPrint method to child  classes
  • Loading branch information
MarharytaBoichenko authored Sep 26, 2022
1 parent 3105d92 commit 3279480
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions submissions/MarharytaBoichenko/oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
class Inhabitant {
constructor(name, species, gender, friends, saying) {
this.name = name;
this.species = species;
this.gender = gender;
this.friends = friends;
this.saying = saying;
this.properties = ["name", "species", "gender", "friends", "saying"];
}
toPrint() {
return this.properties
.filter((prop) => {
return Boolean(this[prop]) != false;
})
.map((prop) => `my ${prop}: ` + this[prop])
.join(", ");
}
}

class Person extends Inhabitant {
constructor(name, gender, friends, saying) {
super(name, "human", gender, friends, saying);
this.hands = 2;
this.legs = 2;
}

toPrint() {
return super.toPrint() + `, my hands: ${this.hands}, my legs: ${this.legs}`;
}
}

class Man extends Person {
constructor(name, friends, saying) {
super(name, "man", friends, saying);
}

toPrint() {
return super.toPrint();
}
}

class Woman extends Person {
constructor(name, friends, saying) {
super(name, "woman", friends, saying);
}

toPrint() {
return super.toPrint();
}
}
class Animal extends Inhabitant {
constructor(name, species, paws, gender, friends, saying) {
super(name, species, gender, friends, saying);
this.paws = paws;
}

toPrint() {
return super.toPrint() + `, my paws: ${this.paws}`;
}
}
class Cat extends Animal {
constructor(name, species, paws, gender, friends) {
super(name, species, paws, gender, friends, "meow");
}

toPrint() {
return super.toPrint();
}
}

class Dog extends Animal {
constructor(name, gender, friends) {
super(name, "dog", 4, gender, friends, "woof");
}

toPrint() {
return super.toPrint();
}
}

class Catwoman extends Cat {
constructor(name, paws, gender, hands, friends) {
super(name, "catwoman", paws, gender, friends);
this.hands = hands;
}

toPrint() {
return super.toPrint() + `, my hands: ${this.hands}`;
}
}

const inhabitants = [
new Man("Bob", ["cat"], "hi"),
new Woman("Kate", ["cat", "Bob"]),
new Cat("Tom", "cat", 4, "male"),
new Dog("Jack", "male", ["cat", "Jill"]),
new Catwoman("Jane", 2, "female", 2, ["Ann"]),
];

inhabitants.forEach((inhabitant) => {
print(inhabitant.toPrint());
});

0 comments on commit 3279480

Please sign in to comment.