Advertisement
PorisulkiP

Ответ подруге

Apr 25th, 2023 (edited)
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function handleCardClick(event) {
  2.   const card = event.currentTarget;
  3.  
  4.   if (card.classList.contains('flipped')) {
  5.     return;
  6.   }
  7.  
  8.   card.classList.add('flipped');
  9.  
  10.   const flippedCards = document.querySelectorAll('.main-game-card.flipped');
  11.  
  12.   if (flippedCards.length === 2) {
  13.     let firstCardImg = flippedCards[0].querySelector('.front-card');
  14.     let secondCardImg = flippedCards[1].querySelector('.front-card');
  15.     setTimeout(() => {
  16.       checkForMatch(firstCardImg, secondCardImg);
  17.     }, 1000);
  18.   }
  19. }
  20.  
  21. function checkForMatch(firstCardImg, secondCardImg) {
  22.   if (firstCardImg.src === secondCardImg.src) {
  23.     firstCardImg.parentElement.classList.add('matched');
  24.     secondCardImg.parentElement.classList.add('matched');
  25.   } else {
  26.     firstCardImg.parentElement.classList.remove('flipped');
  27.     secondCardImg.parentElement.classList.remove('flipped');
  28.   }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement