Loading...

🧩 Memory Matching Game by marketing2advertising

Advertisements

 Game by marketing2advertising

🧩 Memory Matching Game

Click any two cards to find matching pairs

const emojis = [‘🍎’,’🍌’,’πŸ‡’,’πŸ“’,’πŸ’’,’🍍’];
let cards = […emojis, …emojis]; // Duplicate for matching
cards = cards.sort(() => 0.5 – Math.random()); // Shuffle

const gameContainer = document.getElementById(‘memory-game’);
let firstCard = null;
let secondCard = null;
let lockBoard = false;
let matches = 0;

function createCard(emoji, index) {
const card = document.createElement(‘div’);
card.classList.add(‘card’);
card.dataset.emoji = emoji;
card.dataset.index = index;
card.style.width = ’80px’;
card.style.height = ’80px’;
card.style.border = ‘2px solid #000’;
card.style.borderRadius = ‘8px’;
card.style.display = ‘flex’;
card.style.justifyContent = ‘center’;
card.style.alignItems = ‘center’;
card.style.fontSize = ’36px’;
card.style.cursor = ‘pointer’;
card.style.backgroundColor = ‘#f0f0f0’;
card.textContent = ”;
card.addEventListener(‘click’, handleFlip);
gameContainer.appendChild(card);
}

function handleFlip(e) {
if (lockBoard) return;
const card = e.currentTarget;
const emoji = card.dataset.emoji;

if (card === firstCard || card.textContent) return;

card.textContent = emoji;

if (!firstCard) {
firstCard = card;
} else {
secondCard = card;
lockBoard = true;

if (firstCard.dataset.emoji === secondCard.dataset.emoji) {
matches++;
document.getElementById(‘match-msg’).textContent = `βœ… Match! ${matches} / ${emojis.length}`;
resetTurn();
if (matches === emojis.length) {
document.getElementById(‘match-msg’).textContent = “πŸŽ‰ You matched all pairs!”;
}
} else {
setTimeout(() => {
firstCard.textContent = ”;
secondCard.textContent = ”;
resetTurn();
}, 1000);
}
}
}

function resetTurn() {
[firstCard, secondCard] = [null, null];
lockBoard = false;
}

// Initialize game
cards.forEach((emoji, index) => createCard(emoji, index));

  • Related Posts

    🚘 Car Dodging Game by marketing2advertising

     Game by marketing2advertising 🚘 Car Dodging Game on the πŸ›£οΈ Use the arrow keys to dodge the red cars and survive as long as you can! Score: 0 const canvas…

    Spin the Slot Machine 🎰 game by marketing2advertising

    Game πŸŽ°by marketing2advertising 🎰 Spin the Slot Machine πŸ’ πŸ‹ πŸ‡ 🎲 Spin const symbols = [“πŸ’”, “πŸ‹”, “πŸ‡”, “πŸ‰”, “πŸ”””, “πŸ’Ž”]; function spinSlots() { const slot1 = document.getElementById(“slot1”); const slot2…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    VJ Junior – Yakuza Princess

    VJ Junior – Yakuza Princess

    VJ Junior – Conan the Barbarian

    VJ Junior – Conan the Barbarian

    VJ Junior – After burn

    VJ Junior – After burn

    VJ Junior – Chronicles of narnia

    VJ Junior – Chronicles of narnia

    Vj Junior – Day Shift

    Vj Junior – Day Shift

    Vj Junior – Red Ghost

    Vj Junior – Red Ghost
    β–² Ad