title: How is my TicTacToe game returning the winner as X when it was O
body: <p>I am a relatively new programmer and I have created a Tic Tac Toe game with a way to alert the user who won the game. The problem is, when O wins diagonally, It retaines an alert when X won the game. I can't seem to find a problem in the code.</p>
  <p>My source code is at this URL: <a href="https://justpaste.it/6t0zo" rel="nofollow noreferrer">https://justpaste.it/6t0zo</a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Tic Tac Toe&lt;/title&gt;
  &lt;style&gt;
    body {
    "Arial", Times, serif;
  }
  .row div{
  padding: 10px;
  border: 1.25px solid black;
  height: 30px;
  width: 30px;
  float:left;
  }
  .row{
  clear:both;
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  Click to play Tic Tac Toe&lt;br/&gt;
  &lt;p&gt;               &lt;/p&gt;
  &lt;button onclick="location.reload();"&gt;Play Again&lt;/button&gt;
  &lt;p&gt;               &lt;/p&gt;
  &lt;div&gt;
  &lt;div class="row"&gt;
  &lt;div id="0_0" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;div id="1_0" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;div id = "2_0" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row"&gt;
  &lt;div id="0_1" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;div id="1_1" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;div id = "2_1" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row"&gt;
  &lt;div id="0_2" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;div id="1_2" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;div id = "2_2" onclick="place(this)"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;script&gt;
  var currentPlayer = "O";
  var won = false;
  function place(box) {
  if (box.innerText !="" || won) return;
  box.innerText = currentPlayer;
  currentPlayer == "O" ? currentPlayer = "X" : currentPlayer = "O"
  checkGameBoard(currentPlayer);
  }
  function checkGameBoard(currentPlayer) {
  for (var i=0; i &lt;= 2; i++) {
  checkWinner(document.getElementById(i + "_0").innerText,
  document.getElementById(i + "_1").innerText,
  document.getElementById(i + "_2").innerText, currentPlayer);
  checkWinner(document.getElementById("0_" + i).innerText,
  document.getElementById("1_" + i).innerText,
  document.getElementById("2_" + i).innerText, currentPlayer);
  }
  checkWinner(document.getElementById("0_0").innerText,
  document.getElementById("1_1").innerText,
  document.getElementById("2_2").innerText);
  checkWinner(document.getElementById("0_2").innerText,
  document.getElementById("1_1").innerText,
  document.getElementById("2_0").innerText);
  
  }
  function checkWinner(first,second,third, currentPlayer) {
  if(first != "" &amp;&amp; first == second &amp;&amp; first == third) {
    if (currentPlayer == "X"){
      alert(" Winner is O!" );
    }
    else {
      alert(" Winner is X!" );
    }
  won = true
  }
  }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>