forked from OleksiyRudenko/a-tiny-JS-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
105 lines (84 loc) · 3.26 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Refer to https://github.com/OleksiyRudenko/a-tiny-JS-world for the task details
Complete the below for code reviewers' convenience:
Code repository: _put repo URL here_
Web app: _put project's github pages URL here_
*/
// ======== OBJECTS DEFINITIONS ========
// Define your objects here
class Inhabitant {
constructor ({ species, name, gender, saying, friends = "No friends! One man army" }) {
this.species = species
this.name = name
this.gender = gender
this.saying = saying
this.friends = friends
}
toString() {
let inhabitantProps = ["species", "name", "gender", "saying", "friends"].map(prop => this[prop]).join('; ');
return inhabitantProps;
}
}
class Animal extends Inhabitant {
constructor ({ species, name, gender, saying, friends, paws = 4 }) {
super({ species, name, gender, saying, friends })
this.paws = paws
}
toString() {
let animalProps = ["paws"].map(prop => this[prop]).join("; ");
return super.toString() +`; ${animalProps}.`;
}
}
class Dog extends Animal {
constructor ({ name, gender, friends }) {
super({ species: 'dog', name, gender, saying: 'woof-woof', friends })
}
}
class Cat extends Animal {
constructor ({ name, gender, friends }) {
super({ species: 'cat', name, gender, saying: 'meow-meow', friends })
}
}
class HomoSapiens extends Inhabitant {
constructor ({ name, gender, saying, friends, hands = 2, legs = 2 }) {
super({ species: 'human', name, gender, saying, friends })
this.hands = hands
this.legs = legs
}
toString() {
let homoSapiensProps = ["hands", "legs"].map(prop => this[prop]).join("; ");
return super.toString() +`; ${homoSapiensProps}.`;
}
}
class Woman extends HomoSapiens {
constructor({ name, saying, friends }) {
super({ name, gender: 'female', saying, friends })
}
}
class Man extends HomoSapiens {
constructor({ name, saying, friends }) {
super({ name, gender: 'male', saying, friends })
}
}
const dog = new Dog({ name: 'Spike', gender: 'male', friends: ['Dolf', 'Roman', 'Mariia'] })
const cat = new Cat({ name: 'Dolf', gender: 'male'})
const man = new Man({ name: 'Roman', saying: 'Hello!', friends: ['Spike', 'Dolf', 'Mariia'] })
const woman = new Woman({ name: 'Mariia', saying: 'Hi!', friends: ['Spile', 'Dolf', 'Roman'] })
const inhabitants = [dog, cat, man, woman]
inhabitants.forEach((item) => {
print(item)
})
// ======== OUTPUT ========
/* Use print(message) for output.
Default tag for message is <pre>. Use print(message,'div') to change containing element tag.
Message can contain HTML markup. You may also tweak index.html and/or styles.css.
However, please, REFRAIN from improving visuals at least until your code is reviewed
so code reviewers might focus on a single file that is index.js.
*/
/* Print examples:
print('ABC');
print('<strong>ABC</strong>');
print('<strong>ABC</strong>', 'div');
print('human; John; male; 2; 2; Hello world!; Rex, Tom, Jenny');
print('human; <strong>John</strong>; male; 2; 2; <em>Hello world!</em>; Rex, Tom, Jenny');
print('human; <strong>John</strong>; male; 2; 2; <em>Hello world!</em>; Rex, Tom, Jenny', 'div');
*/