script.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const btn = document.getElementById('btn');
  2. btn.addEventListener('click', btnHandler);
  3. document.querySelectorAll(".memory-card").forEach(card => {
  4. card.addEventListener('click', startGame);
  5. })
  6. const result = document.getElementById("textResult");
  7. const card = document.getElementById("card");
  8. const frontFaceCard = document.getElementById("front-face");
  9. const predictValue = {};
  10. let history = "1111";
  11. let gadalka = predictValue[history] ? predictValue[history] : Math.round(Math.random()).toString();
  12. console.log(gadalka)
  13. function startGame(e) {
  14. frontFaceCard.innerText = gadalka;
  15. let value = e.target.innerText;
  16. predictValue[history] = value;
  17. history += value;
  18. history = history.slice(1);
  19. card.classList.toggle('flip');
  20. btn.classList.toggle("hidden");
  21. result.classList.toggle("hidden");
  22. btn.disabled = false;
  23. result.innerText = gadalka === value ? "Угадала!" : "Не угадала!";
  24. document.querySelectorAll(".memory-card").forEach(card => {
  25. card.removeEventListener('click', startGame);
  26. })
  27. }
  28. function btnHandler(){
  29. gadalka = predictValue[history] ? predictValue[history] : Math.round(Math.random()).toString();
  30. console.log(gadalka)
  31. document.querySelectorAll(".memory-card").forEach(card => {
  32. card.addEventListener('click', startGame);
  33. });
  34. card.classList.toggle('flip');
  35. btn.classList.toggle("hidden");
  36. result.classList.toggle("hidden");
  37. btn.disabled = true;
  38. }