-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (79 loc) · 2.58 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
/* 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
const man = {
species: 'human',
name: 'Tom',
gender: 'male',
legs: 2,
hands: 2,
paws: 0,
saying: 'Hello Jenny!',
friends: ['Tom', 'Jenny', 'Rex', 'Selina']
},
woman = {
species: 'human',
name: 'Jenny',
gender: 'female',
legs: 2,
hands: 2,
paws: 0,
saying: 'Hello Tom!',
friends: ['Tom', 'Rex', 'Felix']
},
dog = {
species: 'dog',
name: 'Rex',
gender: 'male',
legs: 0,
hands: 0,
paws: 4,
saying: 'woof-woof!',
friends: ['Tom', 'Jenny']
},
cat = {
species: 'cat',
name: 'Felix',
gender: 'male',
legs: 0,
hands: 0,
paws: 4,
saying: 'meow!',
friends: ['Tom', 'Jenny', 'Selina']
},
catWoman = {
species: 'human',
name: 'Selina',
gender: 'female',
legs: 2,
hands: 2,
paws: 0,
saying: cat.saying,
friends: ['Tom', 'Felix']
};
// ======== 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 createStory = (character, index) => {
let speciesDiff;
if(character.paws > 0) speciesDiff = `<b>${character.paws}</b> paws`;
else speciesDiff = `<b>${character.legs}</b> legs and is <b>${character.hands}</b> hands`;
return `<b>Welcome</b>, wanderer, let me tell you briefly about ${index+1}th our resident - a wonderful <b>${character.species}</b> creature, the name is <b>${character.name}</b>! This member is the owner of ${speciesDiff}, usually the greeting is <i style="text-decoration:underline;"><b>${character.saying}</b></i> and friends of this inhabitant are <b>${character.friends.join(', ')}</b>.`;
};
Array.from([man, woman, cat, dog, catWoman], (obj, index) => print(createStory(obj, index), 'p'));
/* 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');
*/