Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function handleCardClick(event) {
- const card = event.currentTarget;
- if (card.classList.contains('flipped')) {
- return;
- }
- card.classList.add('flipped');
- const flippedCards = document.querySelectorAll('.main-game-card.flipped');
- if (flippedCards.length === 2) {
- let firstCardImg = flippedCards[0].querySelector('.front-card');
- let secondCardImg = flippedCards[1].querySelector('.front-card');
- setTimeout(() => {
- checkForMatch(firstCardImg, secondCardImg);
- }, 1000);
- }
- }
- function checkForMatch(firstCardImg, secondCardImg) {
- if (firstCardImg.src === secondCardImg.src) {
- firstCardImg.parentElement.classList.add('matched');
- secondCardImg.parentElement.classList.add('matched');
- } else {
- firstCardImg.parentElement.classList.remove('flipped');
- secondCardImg.parentElement.classList.remove('flipped');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement