-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
99 lines (89 loc) · 1.81 KB
/
main.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
const musicians = {
trumpetPlayer: `
o
-|-🎺
/\\
`,
guitarist: `
o
-|-🎸
/\\
`,
pianist: `
o
-|-🎹
/\\
`,
saxophonePlayer: `
o
-|-🎷
/\\
`,
violinist: `
o
-|-🎻
/\\
`,
drummer: `
o
-|-🥁
/\\
`,
vocalist: `
o
-|-🎤
/\\
`,
postalHornPlayer: `
o
-|-📯
/\\
`,
}
if (!Object.entries)
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const indexOfMusician = getRandomNumber(0, 7)
const randomNumberBand = getRandomNumber(1, 8)
const printText = function (dictionary) {
objValuesMap = Object.getOwnPropertyNames(dictionary);
objKeysMap = Object.keys(dictionary).map((k) => dictionary[k]);
for (let i = 0; i < objKeysMap.length; i++) {
if (objKeysMap[i] === 1) {
console.log(`there is ${objKeysMap[i]} ${objValuesMap[i]} in this band`);
}
else {
console.log(`there are ${objKeysMap[i]} ${objValuesMap[i]}s in this band`);
}
}
}
const createBand = function (numberOfMembers) {
let nameArray = [];
let dict = {};
for (let i = 0; i < numberOfMembers; i++) {
const indexOfMusician = getRandomNumber(0, 7)
randomIcon = Object.entries(musicians)[indexOfMusician][1];
randomName = Object.entries(musicians)[indexOfMusician][0];
nameArray.push(randomName);
console.log(randomIcon);
}
for (let word of nameArray) {
if (word in dict) {
dict[word] += 1
}
else {
dict[word] = 1
}
}
printText(dict)
}
createBand(randomNumberBand)