title: Tie for tic tac toe?
body: <p>Same tic tac toe game from earlier for my school, I forgot to figure in if the game is a draw... not sure how to to tell players it is a tie. Need help coding how to tell player if game is a tie.  here is my code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;style&gt;
  
          .Square
          {
          width:60px;
          height: 60px;
          text-align:center;
          font-size: 30pt;
          font-weight: bold;
          font-family: Verdana;
          }
      &lt;/style&gt;
  
  &lt;script&gt;
              function startGame()
                  {
                      for (var i = 1; i&lt;= 9; i = i + 1)
                      {
                          clearBox(i);
                      }
  
                  document.turn = "X";
                  if (Math.random()&lt; 0.5)
                  {
                      document.turn = "O";
                  }
                  document.winner = null;
                  setMessage(document.turn + " gets to start.");
              }
  
              function setMessage(msg)
              {
              document.getElementById("message").textContent = msg;
              }
  
              function nextMove(square)
              {
                  if (document.winner != null)
                  {
                      setMessage(document.winner + " Already Won the Game!");
                  }
                  else if (square.textContent == "")
                  {
                      square.textContent = document.turn;
                      switchTurn();
                  }
                  else
                  {
                      setMessage("That Square is Already Used.")
                  }
              }
  
              function switchTurn()
              {
                  if(checkForWinner(document.turn))
                  {
                      setMessage("Congratulations " + document.turn + "! You Win!");
                      document.winner = document.turn;
                  }
                      else if (document.turn == "X")
                          {
                              document.turn ="O";
                              setMessage("It's " + document.turn + "'s turn!");
                          }
                      else
                      {
                          document.turn ="X";
                          setMessage("It's " + document.turn + "'s turn!");
                      }
              }
  
              function checkForWinner(move)
              {
                  var result = false;
                  if(checkRow(1,2,3, move) || 
                     checkRow(4,5,6, move) || 
                     checkRow(7,8,9, move) ||
                     checkRow(1,4,7, move) ||
                     checkRow(2,5,8, move) ||
                     checkRow(3,6,9, move) ||
                     checkRow(1,5,9, move) ||
                     checkRow(3,5,7, move))
                     {
                      result = true;
                     }
                      return result;
  
              }
  
              function checkRow(a,b,c, move)
              {
                  var result = false;
                  if (getBox(a)== move &amp;&amp; getBox(b)== move &amp;&amp; getBox(c)== move)
                  {
                  result = true;
                  }
                  return result;
              }
  
              function getBox(number)
              {
                  return document.getElementById("s" + number).textContent;
              }
  
              function clearBox(number)
              {
                  document.getElementById("s" + number).textContent = "";
              }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body onload= "startGame();" background="http://www.clipartbest.com/cliparts/dcr/eKa/dcreKaqoi.gif"&gt;
      &lt;center&gt;&lt;h1&gt;&lt;font color ="black" size="30"&gt; Tic-Tac-Toe!&lt;/font&gt;&lt;/h1&gt;&lt;/center&gt;
      &lt;center&gt;&lt;div id=message&gt; message will be here &lt;/div&gt;&lt;/center&gt;
      &lt;center&gt;&lt;table border= "15" bgcolor= "#FFFFFF"&gt;
          &lt;tr&gt;
              &lt;td id="s1" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
              &lt;td id="s2" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
              &lt;td id="s3" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="s4" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
              &lt;td id="s5" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
              &lt;td id="s6" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="s7" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
              &lt;td id="s8" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
              &lt;td id="s9" class= "Square" onclick="nextMove(this);"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;&lt;/center&gt;
      &lt;center&gt;&lt;button type="button" onclick=startGame()&gt; Start New Game&lt;/button&gt;&lt;/center&gt;
      &lt;center&gt;&lt;p&gt; Created By Claire Fuesting&lt;/p&gt;&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>