-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (41 loc) · 1.24 KB
/
script.js
File metadata and controls
41 lines (41 loc) · 1.24 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
let cardsNumber = prompt("Digite a quantidade de cartas: ");
while (cardsNumber > 14 || cardsNumber < 4 || cardsNumber % 2 !== 0)
cardsNumber = prompt(
"Quantidade de cartas inválida, insira um número par entre 4 e 14:"
);
let cardsImages = [
"./bobrossparrot.gif",
"./explodyparrot.gif",
"./fiestaparrot.gif",
"./metalparrot.gif",
"./revertitparrot.gif",
"./tripletsparrot.gif",
"./unicornparrot.gif"
];
let activeCards = 0;
function giveCards() {
const card = document.querySelector(".cards");
for (let i = 0; i < cardsNumber; i++) {
card.innerHTML =
card.innerHTML +
`<div class="front-face" onclick="turnCard(this)">
<img src=${cardsImages[i]} />
</div>`;
}
}
giveCards();
const testActiveCards = document.querySelectorAll(".turned");
function turnCard(selector) {
if (activeCards <= 2) {
if (testActiveCards[0] === undefined) {
selector.classList.remove("front-face");
selector.classList.add("turned");
activeCards++;
}
if (testActiveCards[1] === undefined) {
selector.classList.remove("front-face");
selector.classList.add("turned");
activeCards++;
}
}
}