function incrementAttempts(){
attempts++;
attemptsHolder.textContent = attempts;
}
// Function to check if the chosen cards match
function checkForMatch() {
const [card1, card2] = chosenCards;
const [cardId1, cardId2] = chosenCardsIds;
// If the cards match, update foundCards count and display
if (card1 === card2) {
foundCards += 2;
foundHolder.textContent = foundCards;
if (foundCards === cardsInGame) {
// const final = attempts;
setTimeout(()=>{
console.log(attempts);
alert(`Congratulations! You found all the pairs in ${attempts} attempts.`);
},0);
}
} else {
// If the cards don't match, flip them back
document.querySelector(`[data-id="${cardId1}"]`).textContent = '';
document.querySelector(`[data-id="${cardId2}"]`).textContent = '';
}
// Clear the chosen cards arrays
chosenCards = [];
chosenCardsIds = [];
// Increase attempts count and display
incrementAttempts()
}
function incrementAttempts(){
attempts++;
attemptsHolder.textContent = attempts;
}
// Function to check if the chosen cards match
function checkForMatch() {
const [card1, card2] = chosenCards;
const [cardId1, cardId2] = chosenCardsIds;
// If the cards match, update foundCards count and display
if (card1 === card2) {
foundCards += 2;
foundHolder.textContent = foundCards;
if (foundCards === cardsInGame) {
// const final = attempts;
setTimeout(()=>{
console.log(attempts);
alert(`Congratulations! You found all the pairs in ${attempts} attempts.`);
},0);
}
} else {
// If the cards don't match, flip them back
document.querySelector(`[data-id="${cardId1}"]`).textContent = '';
document.querySelector(`[data-id="${cardId2}"]`).textContent = '';
}
// Clear the chosen cards arrays
chosenCards = [];
chosenCardsIds = [];
// Increase attempts count and display
incrementAttempts()
}