在记忆比赛中显示移动列表

时间:2019-02-18 01:02:18

标签: javascript

我正在尝试在javascript内存匹配游戏中显示移动列表,请给我一些帮助

card.addEventListener('click',()=>{
    if (count<2) {
        count++;

        if (count===1) {
            firstGuess=card.dataset.name;
            card.classList.toggle('is-flipped')
        }else{
            secondGuess = card.dataset.name;
            card.classList.toggle('is-flipped')
        }


      if (firstGuess !== '' && secondGuess !== '') {


        if(firstGuess===secondGuess){

            setTimeout(match, delay);
           setTimeout(reset,delay);



          }else{
            setTimeout(reset,delay);
          }

      }


   }

})

如何在html页面上显示移动数量

1 个答案:

答案 0 :(得分:1)

//This variable will keep track of the count
let count = 0;
//This is the element that will display the count
const countEl = document.querySelector('#move-count');
document.querySelector('input').addEventListener('click', e => {
  count += 1;
  countEl.innerHTML = count;
});
<div id="move-count"></div>
<input type="button" value="Add 1" />