0
    <html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=windows-1252"
    <title> "tic tac toe"</title>
    <script language="JavaScript">
        var Next = "X";
        var count = "O";
        var square= new Array()
        for (var i=0; i<9; i++) square[i] = true;
        function makeMove(squareindex)                  
        {
            if (square [squareindex] == true;
            }
            (square [squareindex] == true;
                count++;
                document.getElementById(squareindex).value = ""+next+"";
                if Next == "X";
                {
                    Next == "O";
                }
                else
                {
                    Next == "X";
                }
                if (count == 9) document.getElementById("toeDisplay").innerHTML="Game Over!";
                else document.getElementById("toeDisplay").innerHTML= It is/""+next+""/'s turn";
            }
            else
            {
                document.getElementById("toeDisplay").innerHTML = "Fail";
            }
        }
    </script>
</head>
<body>
    &nbsp;&nbsp;&nbsp;tic tac toe
    <table border=1 id="tictactable"><form name="tic tac toe"></form>   
        <tr>
            <td id="toeDisplay" colspan=4 align=center bgcolor=white> It is "X"'s turn</td>
        </tr>
        <tr>                                                         
            <td align=center><INPUT id="0" TYPE="button" value="  "onClick="makeMove(0)"></td>          
            <td align=center><INPUT id="1" TYPE="button" value="  "onClick="makeMove(1)"></td>  
            <td align=center><INPUT id="2" TYPE="button" value="  "onClick="makeMove(2)"></td>
        </tr>                                                  
        <tr>                                                
            <td align=center><INPUT id="3" TYPE="button" value="  "onClick="makeMove(3)"></td>      
            <td align=center><INPUT id="4" TYPE="button" value="  "onClick="makeMove(4)"></td> 
            <td align=center><INPUT id="5" TYPE="button" value="  "onClick="makeMove(5)"></td>
        </tr>
        <tr>
            <td align=center><INPUT id="6" TYPE="button" value="  "onClick="makeMove(6)"></td>
            <td align=center><INPUT id="7" TYPE="button" value="  "onClick="makeMove(7)"></td>
            <td align=center><INPUT id="8" TYPE="button" value="  "onClick="makeMove(8)"></td>
        </tr> 
</table>        

</body>
</html>

Hi there! I got this code for a JavaScript tic-tac-toe program and cant get it to work. What am i doing wrong? I made spell checks and didn't find any thing and still it wont work. Its supposed to function like a normal game of tic-tac-toe. Your "X" and the computer would be "O". It would make the computer make a move when you hit a button, and i cant seem to get that to work.

2
  • Numerous typos and errors in this. Unclosed parentheses, brackets going wrong way. Work through the errors in chrome developer tools console. Commented Jan 4, 2013 at 23:58
  • Have a look at your html also, it's not entirely valid. Commented Jan 5, 2013 at 0:05

2 Answers 2

1

This is invalid code... if (square [squareindex] == true; is not proper JavaScript syntax. You would have to do if (square [squareindex] == true) {.

If you open the Chrome Developer Tools, you'd see errors in the Console:

enter image description here

The code is sprinkled with these kinds of issues. Fix them and then try again. You can refer to Douglas Crockford's JavaScript: The Good Parts as a good reference for syntax.

Sign up to request clarification or add additional context in comments.

Comments

1

Well, just look at the colour-coding, for one. You're missing quotes in places, especially your "it is ...'s turn".

Aside from that, your number one problem is the very first if, you have a semicolon instead of a closing parenthesis.

You should use a code editor such as Notepad++ that includes syntax highlighting and bracket matching, it makes finding errors like this much easier ;)

EDIT: I've made an example implementation of Tic-Tac-Toe. Link. Take a look at the code used to make it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.