forked from OleksiyRudenko/a-tiny-JS-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Refer to https://github.com/OleksiyRudenko/a-tiny-JS-world for the task details
Complete the below for code reviewers' convenience:
Code repository:https://github.com/AnnaGrynchuk/a-tiny-JS-world
Web app: _put project's github pages URL here_
*/
// ======== OBJECTS DEFINITIONS ========
class Inhebitant {
constructor(species, name, gender, saying, legs) {
this.species = species;
this.name = name;
this.gender = gender;
this.saying = saying;
this.legs = legs;
}
joinInhebitantsInString(){
return [this.species,this.name,this.gender,this.saying,this.legs,].join("-");
}
}
class Human extends Inhebitant {
constructor(name, gender, saying, hands=2 ) {
super('human', name, gender, saying, 2);
this.hands = hands;
}
joinInhebitantsInString(){
return super.joinInhebitantsInString() + "-" + this.hands;
}
}
class Dog extends Inhebitant {
constructor( name, gender, saying) {
super('dog', name, gender, saying, 4);
}
}
class Cat extends Inhebitant {
constructor(name, gender, saying) {
super('cat', name, gender, saying, 4);
}
}
const dog = new Dog('Toby', 'male', 'woof-woof!');
const cat = new Cat('Persik', 'male', 'meawww-meaww!');
const woman = new Human('Poly', 'female', 'I am hungry!');
const man = new Human('Alex', 'male', 'Lets go to bar!');
let inhebitants = [dog,cat,woman,man];
inhebitants.forEach(item =>print(item.joinInhebitantsInString()));