A classic card-matching memory game built with JavaScript.
memory-game/
├── index.html # HTML structure
├── style.css # Styles and animations
├── script.js # Game logic
└── README.md # This file
const cards = [
'🍎', '🍎',
'🍌', '🍌',
'🍇', '🍇',
'🍊', '🍊'
];
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
let firstCard = null;
let secondCard = null;
let lockBoard = false;
let matches = 0;
let moves = 0;
function checkMatch() {
if (firstCard.dataset.value === secondCard.dataset.value) {
// Match!
firstCard.classList.add('matched');
secondCard.classList.add('matched');
resetCards();
} else {
// No match - flip back after delay
lockBoard = true;
setTimeout(() => {
firstCard.classList.remove('flipped');
secondCard.classList.remove('flipped');
resetCards();
}, 1000);
}
}
.card {
position: relative;
transform-style: preserve-3d;
transition: transform 0.6s;
}
.card.flipped {
transform: rotateY(180deg);
}
.card-front, .card-back {
position: absolute;
backface-visibility: hidden;
}
.card-back {
transform: rotateY(180deg);
}