-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 2.02 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
const emoji = ["😂", "😂", "😍", "😍", "😎", "😎", "❤", "❤", "😵", "😵", "🤡", "🤡", "😡", "😡", "💩", "💩"];
var shuf_emojis = emoji.sort(() => (Math.random() > .5) ? 2 : -1);
var confettiSettings = { target: 'my-canvas' };
var confetti = new ConfettiGenerator(confettiSettings);
confetti.render();
for (var i = 0; i < emoji.length; i++) {
let box = document.createElement('div')
box.className = 'item';
box.innerHTML = shuf_emojis[i]
box.onclick = function () {
this.classList.add('boxOpen')
setTimeout(function () {
if (document.querySelectorAll('.boxOpen').length > 1) {
if (document.querySelectorAll('.boxOpen')[0].innerHTML == document.querySelectorAll('.boxOpen')[1].innerHTML) {
document.querySelectorAll('.boxOpen')[0].classList.add('boxMatch')
document.querySelectorAll('.boxOpen')[1].classList.add('boxMatch')
document.querySelectorAll('.boxOpen')[1].classList.remove('boxOpen')
document.querySelectorAll('.boxOpen')[0].classList.remove('boxOpen')
if (document.querySelectorAll('.boxMatch').length == emoji.length) {
document.querySelector('.popup').classList.add('active')
document.querySelector('#my-canvas').classList.add('active')
document.querySelector('.close').onclick = function () {
document.querySelector('.popup').classList.remove('active')
document.querySelector('#my-canvas').classList.remove('active')
}
}
}
else {
document.querySelectorAll('.boxOpen')[1].classList.remove('boxOpen');
document.querySelectorAll('.boxOpen')[0].classList.remove('boxOpen');
}
}
}, 500)
}
document.querySelector('.game').appendChild(box);
}