-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (52 loc) · 1.05 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
var validEmojis = [
'🏠',
'🏡',
'🏚',
'🏭',
'🏢',
'🏬',
'🏣',
'🏤',
'🏥',
'🏦',
'🏨',
'🏪',
'🏫',
'🏩',
'💒',
'🏛',
'⛪️'
];
var i = 0;
do {
var block = document.createElement('DIV');
block.className = 'tile';
var moji = document.createElement('DIV');
moji.className = 'emoji';
moji.appendChild(
document.createTextNode(
validEmojis[Math.floor(Math.random() * validEmojis.length)]
)
);
block.appendChild(moji);
document.getElementsByClassName('container')[0].appendChild(block);
i++;
} while (i < 36);
document
.getElementsByClassName('container')[0]
.addEventListener('click', event => {
clickTarget(event.target);
});
function clickTarget(element) {
var moji;
if (element.className === 'tile') {
moji = element.childNodes[0];
} else if (element.className === 'emoji') {
moji = element;
}
changeTile(moji);
}
function changeTile(moji) {
var newEmoji = validEmojis[Math.floor(Math.random() * validEmojis.length)];
moji.innerHTML = newEmoji;
}