let turn = 'O'; ------------------------------------------- ①
    const callback = (event) => { ----------------------------- ②
      if (event.target.textContent !== '') { // 빈칸이 아닌가? 
        console.log('빈칸이 아닙니다.');
      } else { // 빈칸이면
        console.log('빈칸입니다'); 
        event.target.textContent = turn;
        turn = turn === 'X' ? 'O' : 'X'; ---------------------- ④
      }
    };
    for (let i = 1; i <= 3; i++) {
      const $tr = document.createElement('tr'); 
      const cells = [];
      for (let j = 1; j <= 3; j++) {
        const $td = document.createElement('td'); 
        $td.addEventListener('click', callback); -------------- ③
        cells.push($td);
        $tr.appendChild($td);
      }
      rows.push(cells);
      $table.appendChild($tr);
    }
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.