Proper Syntax for Declaring a Draw in Tic Tac Toe
<p>I am making a tic tac toe game. Someone already taught me how to get the winner declared and stop further play.</p>

<p>There are two persistent problems. The first is that when the wins are straight across, the counters add 1 to the x wins and 2 to the o wins. The second issue is that I can't get the game to call a draw. I have tried else if without results.</p>

<p>Here is the whole js and the game can be seen at: <a href="http://jvonhausen.com/final/p19/" rel="nofollow">http://jvonhausen.com/final/p19/</a></p>

<pre><code>jQuery(function() {

    $('#start').click(clear_squares);

    $('.square').click(function () {    
        square_stuff(this);
    });

});

var player_x = true; 
var complete = false; 
var winner = '';
var x_wins = 0;
var o_wins = 0;
var draw = 0;

function clear_squares () {
    localStorage.setItem('x_count', x_wins); 
    localStorage.setItem('o_count', o_wins); 
    localStorage.setItem('draw_count', draw); 

    $('.square').html(''); 

    player_x = true;
    $('#output').html('turn: x');

    complete = false; //allows for new game
}


function square_stuff (square) {
    if (!complete) {
        if ($(square).html() == '') {       
            if (player_x == true) {
                $(square).html('x');
                player_x = false;               
            } else {            
                $(square).html('o');
                player_x = true;                
            }
        }
    }   
    check_squares();
}

function check_squares () {
    complete = true;
    var values = new Array(); 
    var winner = '';

    $('.square').each(function () {     
        values.push( $(this).html());
        if ($(this).html() == '') complete = false;
        if ( !winner &amp;&amp; values[0] == values[1] &amp;&amp; values[1] == values[2] ) winner = values[0];
        if ( !winner &amp;&amp; values[3] == values[4] &amp;&amp; values[4] == values[5] ) winner = values[4];
        if ( !winner &amp;&amp; values[6] == values[7] &amp;&amp; values[7] == values[8] ) winner = values[7];
        if ( !winner &amp;&amp; values[0] == values[3] &amp;&amp; values[3] == values[6] ) winner = values[3];
        if ( !winner &amp;&amp; values[1] == values[4] &amp;&amp; values[4] == values[7] ) winner = values[1];
        if ( !winner &amp;&amp; values[2] == values[5] &amp;&amp; values[5] == values[8] ) winner = values[5];
        if ( !winner &amp;&amp; values[0] == values[4] &amp;&amp; values[4] == values[8] ) winner = values[8];
        if ( !winner &amp;&amp; values[2] == values[4] &amp;&amp; values[4] == values[6] ) winner = values[2];      
        if (winner) {           
            complete = true;
            $('#output').html('winner: ' + winner);
            if ($(this).html() == 'x') {
                localStorage.setItem('x_count', x_wins); 
                x_wins++;
                $('#wins_x').val(x_wins);
            } 
            if ($(this).html() == 'o') {
                localStorage.setItem('o_count', o_wins); 
                o_wins++;
                $('#wins_o').val(o_wins);
            }
            if (winner == '' &amp;&amp; complete == true) { 
                $('#output').html('no winner');
                localStorage.setItem('draw_count', draw); 
                draw++;
                $('#draws').val(draw);
            }   
        }                   
        if (winner == '' &amp;&amp; complete == false) {    
            if (player_x == true) {     
                $('#output').html('turn: x');
            } else {        
                $('#output').html('turn: o');
            }       
        }
    });

}
</code></pre>
