0
function checkIfGameIsOver() {
    if (
      (tableModule.table[0] === 'X' &&
        tableModule.table[1] === 'X' &&
        tableModule.table[2] === 'X') ||
      (tableModule.table[3] === 'X' &&
        tableModule.table[4] === 'X' &&
        tableModule.table[5] === 'X') ||
      (tableModule.table[6] === 'X' &&
        tableModule.table[7] === 'X' &&
        tableModule.table[8] === 'X') ||
      (tableModule.table[0] === 'X' &&
        tableModule.table[3] === 'X' &&
        tableModule.table[6] === 'X') ||
      (tableModule.table[1] === 'X' &&
        tableModule.table[4] === 'X' &&
        tableModule.table[7] === 'X') ||
      (tableModule.table[2] === 'X' &&
        tableModule.table[5] === 'X' &&
        tableModule.table[8] === 'X') ||
      (tableModule.table[0] === 'X' &&
        tableModule.table[4] === 'X' &&
        tableModule.table[8] === 'X') ||
      (tableModule.table[2] === 'X' &&
        tableModule.table[4] === 'X' &&
        tableModule.table[6] === 'X')
  ) {
    const winner = document.querySelector('.winner');
    winner.textContent = 'winner is X';
  }
}

This works fine, but I would like to reduce the code. Table is simple array of just X or O's or empty.

This is only for X so i have to duplicate this. Is there any better solution?

Michael M.
  • 10,486
  • 9
  • 18
  • 34

0 Answers0