title: How to check a cell for an element in tic-tac-toe game?
body: <p>I am currently learning JS and have created my first tic-tac-toe game. When I put any character, I assign a private class to them, but I ran into a problem, how do I check that a cell that already has an element is occupied, that is, how can I forbid assigning a second class and forbid replacing an element</p>
  <pre><code>for(let i = 0; i &lt; 9; i++) {
      document.getElementById('game').innerHTML+='&lt;div class=&quot;block&quot;&gt;&lt;/div&gt;';
  }
  
  let game = document.getElementById('game');
  let blocks = document.querySelectorAll('.block');
  let res = document.querySelector('.result');
  let btnGame = document.querySelector('.new-game');
  let currentPlayer = document.getElementById('cur-plr');
  
  let step = false;
  let player = '';
  let score = {
      'x': 0,
      'o': 0,
      'd': 0,
  };
  let count = 0;
  let playerOne = 'x';
  let playerSecond = '0';
  
  const isPlayerOneWin = (blocks, comb, i) =&gt; blocks[comb[i][0]].classList.contains('playerOne') &amp;&amp; blocks[comb[i][1]].classList.contains('playerOne') &amp;&amp; blocks[comb[i][2]].classList.contains('playerOne');
  
  const isPlayerSecondWin = (blocks, comb, i) =&gt; blocks[comb[i][0]].classList.contains('playerSecond') &amp;&amp; blocks[comb[i][1]].classList.contains('playerSecond') &amp;&amp; blocks[comb[i][2]].classList.contains('playerSecond');
  
  function AddClassActive (blocks, comb, i) {
      blocks[comb[i][0]].classList.add('active');
      blocks[comb[i][1]].classList.add('active');
      blocks[comb[i][2]].classList.add('active');
  };
  
  function AddClassNegative (blocks, comb, i) {
      blocks[comb[i][0]].classList.add('negative');
      blocks[comb[i][1]].classList.add('negative');
      blocks[comb[i][2]].classList.add('negative');
  };
  
  function stepPlayerOne(target) {
      target.innerHTML = playerOne
      target.classList.add('playerOne');
      count++;
  };
  
  function stepPlayerSecond(target) {
      target.innerHTML = playerSecond
      target.classList.add('playerSecond');
      count++;
  };
  
  function init(e) {
       if(!step) stepPlayerOne(e.target); 
       else stepPlayerSecond(e.target);
       step = !step;
       player = player == '0' ? 'x' : '0';
       currentPlayer.innerHTML = player.toUpperCase();
       checkWin();
  
  };
  
  function newGame() {
      step = false;
      count= 0;
      res.innerText = '';
      blocks.forEach(item =&gt; {
          item.innerHTML = '';
          currentPlayer.innerHTML = '';
          item.classList.remove('playerOne', 'playerSecond', 'active', 'negative');
          game.addEventListener('click', init);
          updateScore()
      })
  };
  
  function updateScore() {
      document.getElementById('sX').innerHTML = score.x;
      document.getElementById('sO').innerHTML = score.o;
      document.getElementById('sD').innerHTML = score.d;
  }
  
  function checkWin() {
      let comb = [
          [0, 1, 2],
          [3, 4, 5],
          [6, 7, 8],
          [0, 3, 6],
          [1, 4, 7],
          [2, 5, 8],
          [0, 4, 8],
          [2, 4, 6],
      ];
      
      for(let i = 0; i &lt; comb.length; i++) {
  
          if (isPlayerOneWin(blocks, comb, i)) {
              AddClassActive(blocks, comb, i);
              res.innerText = 'Cross Win';
              game.removeEventListener('click', init)
              score.x += 1
          }
  
          else if (isPlayerSecondWin(blocks, comb, i)) {
              AddClassActive(blocks, comb, i)
              res.innerText = 'Zero Win';
              game.removeEventListener('click', init)
              score.o += 1
          }
  
          else if (count == 9 &amp;&amp; i === 7) {
              AddClassNegative(blocks, comb, i)
              res.innerText = 'Draw, try again';
              game.removeEventListener('click', init);
              console.log(score.d);
              score.d += 1;
          }
      }
  };
  
  btnGame.addEventListener('click', newGame);
  game.addEventListener('click', init);
  
  </code></pre>
  <p>I tried to do a check, but I guess I'm not doing it right here, tell me how can I do it right?
  that's an example</p>
  <pre><code>function stepPlayerSecond(target) {
      if(target.innerHTML = playerSecond) {
          target.classList.add('playerSecond');
      }
      else {
          remove();
      }
      count++;
  };
  </code></pre>