const btn = document.getElementById('btn'); btn.addEventListener('click', btnHandler); document.querySelectorAll(".memory-card").forEach(card => { card.addEventListener('click', startGame); }) const result = document.getElementById("textResult"); console.log(result.innerText); const card = document.getElementById("card"); const frontFaceCard = document.getElementById("front-face"); const predictArray = []; for (let i = 0; i <= 1; i++) { let arrI = [] for (let j = 0; j <= 1; j++) { let arrJ = []; for (let k = 0; k <= 1; k++) { let arrK = []; arrK[0] = -1; arrK[1] = -1; arrJ[k] = arrK; } arrI[j] = arrJ } predictArray[i] = arrI; } const history = [1, 1, 1, 1]; let gadalka = predictArray[1][1][1][1] > -1 ? predictArray[1][1][1][1] : Math.round(Math.random()); console.log(gadalka) function startGame(e) { frontFaceCard.innerText = gadalka; let value = Number(e.target.innerText); predictArray[history[0]][history[1]][history[2]][history[3]] = value; history.push(Number(value)); history.shift(); card.classList.toggle('flip'); btn.classList.toggle("hidden"); result.classList.toggle("hidden"); btn.disabled = false; result.innerText = gadalka === value ? "Угадала!" : "Не угадала!"; document.querySelectorAll(".memory-card").forEach(card => { card.removeEventListener('click', startGame); }) } function btnHandler(){ gadalka = predictArray[history[0]][history[1]][history[2]][history[3]] > -1 ? predictArray[history[0]][history[1]][history[2]][history[3]] : Math.round(Math.random()); console.log(gadalka) document.querySelectorAll(".memory-card").forEach(card => { card.addEventListener('click', startGame); }); card.classList.toggle('flip'); btn.classList.toggle("hidden"); result.classList.toggle("hidden"); btn.disabled = true; }