-
-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathindex.js
More file actions
140 lines (127 loc) · 3.4 KB
/
Copy pathindex.js
File metadata and controls
140 lines (127 loc) · 3.4 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
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: https://github.com/lometari/a-tiny-JS-world
Web app: https://lometari.github.io/a-tiny-JS-world/
*/
// ======== OBJECTS DEFINITIONS ========
// Define your objects here
let dwellers = [];
class Dweller {
constructor(species, name, sex, phrase, chums) {
this.species = species;
this.name = name;
this.sex = sex;
this.phrase = phrase;
this.chums = chums;
dwellers.push(this);
}
sayFirst() {
return (
"Hi! I'm " +
this.name +
"! " +
"About me: " +
this.species +
", " +
this.sex +
". "
);
}
sayMiddle() {}
sayLast() {
return (
"Love to say: " +
this.phrase +
" " +
"I love hanging out with " +
this.chums +
". "
);
}
introduce() {
return this.sayFirst() + this.sayMiddle() + this.sayLast();
}
}
class Human extends Dweller {
constructor(species, name, sex, phrase, chums, handsAmount, legsAmount) {
super(species, name, sex, phrase, chums);
this.handsAmount = handsAmount;
this.legsAmount = legsAmount;
}
sayMiddle() {
return (
"I got " + this.handsAmount + " hands & " + this.legsAmount + " legs. "
);
}
connection() {
return (theCatWoman.phrase = cat.phrase);
}
}
class Animal extends Dweller {
constructor(species, name, sex, phrase, chums, pawsAmount) {
super(species, name, sex, phrase, chums);
this.pawsAmount = pawsAmount;
}
sayMiddle() {
return "I got " + this.pawsAmount + " paws. ";
}
}
const man = new Human(
"human",
"Joey",
"male",
'"How you doin\'?"',
"Halle, Phoebe, Alfa, Tima",
2,
2,
);
const woman = new Human(
"human",
"Phoebe",
"female",
'"Smelly ca-a-a-a-at!"',
"Joey, Alfa, Tima",
2,
2,
);
const cat = new Animal("cat", "Tima", "male", "Meow!", "Halle", 4);
const dog = new Animal(
"dog",
"Alfa",
"female",
"Bow-wow!",
"Joey, Phoebe, Tima",
4,
);
const theCatWoman = new Human(
"Super-human",
"Halle",
"female",
[cat.phrase],
"Tima",
2,
2,
);
cat.phrase = "Mi-mi-meow!";
// ======== 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.
*/
for (let i = 0; i < dwellers.length; i++) {
if (dwellers[i].species === "Super-human") {
dwellers[i].connection();
}
print(dwellers[i].introduce());
}
/* 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');
*/