-
-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathindex.js
More file actions
177 lines (148 loc) · 6.62 KB
/
Copy pathindex.js
File metadata and controls
177 lines (148 loc) · 6.62 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { print } from './js/lib.js';
/* 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 InhabitantsOfTheWorld {
constructor (species, name, gender, legs, saying) {
this.species = species;
this.name = name;
this.gender = gender;
this.legs = legs;
this.saying = saying;
this.friends = [];
}
addFriends(nameFriend) {
return this.friends = [...this.friends, ... nameFriend]
}
}
class Human extends InhabitantsOfTheWorld {
constructor (name, gender, hands, saying) {
super('human', name, gender, 2, saying);
this.hands = hands;
}
}
class Man extends Human {
constructor (name, saying) {
super(name, 'male', 2, saying);
}
}
class Woman extends Human {
constructor (name, saying) {
super(name, 'female', 2, saying);
}
}
class Animal extends InhabitantsOfTheWorld {
constructor (species, name, gender, saying) {
super(species, name, gender, 4, saying);
}
}
class Dog extends Animal {
constructor (name, saying) {
super('dog', name, 'male', saying);
}
}
class Cat extends Animal {
constructor (name, saying) {
super('cat', name, 'female', saying);
}
}
const man = new Man ('Myk', 'hello bro!');
const woman = new Woman ('Magda', "I'll kill you!");
const dog = new Dog ('Caesar', 'woof-woof!');
const cat = new Cat ('Musya', 'meow-meow!');
man.addFriends([dog.name, cat.name, woman.name]);
woman.addFriends([dog.name, cat.name, man.name]);
dog.addFriends([cat.name, man.name, woman.name]);
cat.addFriends([dog.name, man.name, woman.name]);
// ======== 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.
*/
const inhabitants = [dog, cat, man, woman];
inhabitants.map(({species, name, gender, legs, hands = 0, saying, friends}) =>
print(`species: <strong style="color: darkblue">${species}</strong>;
name: <strong style="color: red">${name}</strong>;
gender: <strong style="color: green">${gender}</strong>;
legs: <strong style="color: black">${legs}</strong>;
hands: <strong style="color: gray">${hands}</strong>;
saying: <strong style="color: blue">${saying}</strong>;
friends: <strong style="color: darkorchid">${friends}</strong>;`));
/* 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');
*/
///////////////////// FACTORY-FUNCTION /////////////////////////////
// let InhabitantsOfTheWorld = {
// addFriends(nameFriend) {
// return this.friends = [...this.friends, ... nameFriend]
// },
// getDog() {
// return {species: 'dog', name: this.name, gender: this.gender, legs: this.legs, hands: 0, saying: 'woof-woof!', friends: this.friends};
// },
// getCat() {
// return {species: 'cat', name: this.name, gender: this.gender, legs: this.legs, hands: 0, saying: 'meow-meow!', friends: this.friends};
// },
// getMan() {
// return {species: 'man', name: this.name, gender: this.gender, legs: this.legs, hands: this.hands, saying: this.saying, friends: this.friends};
// },
// getWoman() {
// return {species: 'woman', name: this.name, gender: this.gender, legs: this.legs, hands: this.hands, saying: this.saying, friends: this.friends};
// },
// };
// let CreateInhabitantsOfTheWorld = function (name, gender, legs, hands, saying) {
// let inhabitant = Object.create(InhabitantsOfTheWorld);
// inhabitant.name = name,
// inhabitant.gender = gender,
// inhabitant.legs = legs,
// inhabitant.hands = hands,
// inhabitant.saying = saying;
// inhabitant.friends = [];
// return inhabitant;
// }
// let dog = CreateInhabitantsOfTheWorld('Caesar', 'male', 4);
// let cat = CreateInhabitantsOfTheWorld('Musya', 'female', 4);
// let man = CreateInhabitantsOfTheWorld('Myk', 'male', 2, 2, 'hello bro!');
// let woman = CreateInhabitantsOfTheWorld('Magda', 'female', 2, 2, "I'll kill you!");
// dog.addFriends([cat.name, man.name, woman.name]);
// cat.addFriends([dog.name, man.name, woman.name]);
// man.addFriends([dog.name, cat.name, woman.name]);
// woman.addFriends([dog.name, cat.name, man.name]);
// dog = dog.getDog();
// cat = cat.getCat();
// man = man.getMan();
// woman = woman.getWoman();
// // ======== 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.
// */
// const inhabitants = [dog, cat, man, woman];
// inhabitants.map(({species, name, gender, legs, hands, saying, friends}) =>
// print(`species: <strong style="color: darkblue">${species}</strong>;
// name: <strong style="color: red">${name}</strong>;
// gender: <strong style="color: green">${gender}</strong>;
// legs: <strong style="color: black">${legs}</strong>;
// hands: <strong style="color: gray">${hands}</strong>;
// saying: <strong style="color: blue">${saying}</strong>;
// friends: <strong style="color: darkorchid">${friends}</strong>;`));
// /* 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');
// */