forked from OleksiyRudenko/a-tiny-JS-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (61 loc) · 1.63 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Inhabitants {
constructor(species, name, gender, legs, saying) {
this.species = species;
this.name = name;
this.gender = gender;
this.legs = legs;
this.saying = saying;
}
sayHi() {
let template = [
`${this.saying}`,
`My name is ${this.name}.`,
`I am a ${this.species}.`,
`My gender is ${this.gender}.`,
`I have ${this.legs} legs`
];
return template.join(' ');
}
}
class Human extends Inhabitants {
constructor(name, gender, saying) {
super('human', name, gender, 2, saying);
this.hands = 2;
}
sayHi() {
return (
super.sayHi() + ` and ${this.hands} hands.`
)
}
}
class Woman extends Human {
constructor(name, saying) {
super(name, 'female', saying)
}
}
class Man extends Human {
constructor(name, saying) {
super(name, 'male', saying)
}
}
class Animal extends Inhabitants {
constructor(species, name, gender, saying) {
super(species, name, gender, 4, saying)
}
}
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)
}
}
const woman = new Woman('Emilia', 'Hello, World!');
const man = new Man('Efrain', 'Hola! Mucho gusto!');
const cat = new Cat('Fluffy', 'female', 'Meow!');
const dog = new Dog('Buddy', 'male', 'Woof-woof!');
let inhabitants = [woman, man, cat, dog];
inhabitants.forEach(element => print(element.sayHi()));