const btn = document.getElementById('btn');
btn.addEventListener('click', btnHandler);
document.querySelectorAll(".memory-card").forEach(card => {
    card.addEventListener('click', startGame);
})
const result = document.getElementById("textResult");
const card = document.getElementById("card");
const frontFaceCard = document.getElementById("front-face");

const predictValue = {};



let history = "1111";
let gadalka = predictValue[history]  ? predictValue[history] : Math.round(Math.random()).toString();
console.log(gadalka)

function startGame(e) {
    frontFaceCard.innerText = gadalka;
    let value = e.target.innerText;
    predictValue[history] = value;
    history += value;
    history = history.slice(1);

    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 = predictValue[history]  ? predictValue[history] : Math.round(Math.random()).toString();
    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;
}