-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (25 loc) · 840 Bytes
/
script.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
const cardArray = [
{
id: 1,
name: "powerCard",
state: false,
"back-image": "assets/powercard.jpg",
"front-image": "assets/cardpattern.jpg",
},
];
const cardsContainerElement = document.querySelector("#cards-container");
// Generating card elements
cardArray.forEach((card) => {
const cardElement = document.createElement("div");
cardElement.classList.add("card");
cardsContainerElement.appendChild(cardElement);
cardElement.innerHTML = `
<img class="front" src="${card["front-image"]}" alt="Card Front" />
<img class="back" src="${card["back-image"]}" alt="Card Back" />
`;
cardElement.addEventListener("click", () => flipCards(card, cardElement));
});
function flipCards(card, cardElement) {
card.state = !card.state;
cardElement.classList.toggle("flipped", card.state);
}