by WJClancey » Wed Nov 10, 2010 6:10 pm
Hi Josh,
I'm an AI professional at NASA with a PhD in computer science and have been asked to look at your question.
I am impressed by what you have so far. I don't know if you've made more progress since you posted your question, but I'll tell you what I see in case it might still be useful. I have never programmed a script in HTML, but I can see a few syntax issues in the code you posted.
First, you are almost certainly correct that you shouldn't have two definitions with the same function name. So I would start by deleting the short version, which looks like this --
function squareclicked(square)
{
square.value = 'X';
}
Next, you might want to use indentation in the definition of squareclicked so you can be sure you have matched up the curly brackets.
I notice that in this squareclicked where the first alert appears, the function seems to be missing a curly bracket to mark where the definition ends.
else
alert('That square has already been played.');
}
This bracket that completes the If/then/else, but then another fragment begins with a variable declaration. So you need another "}" to close off the squareclicked definition and then delete the fragment that comes after it (there's a variable declaration but no function header).
So in summary, taking it from the top -- after "var xTurn = true;" you'd have the function definitions for newgame and for squareclicked, and that would be the end of the script you've written here (i.e., </script> would appear after squareclicked's definition).
Please post another question if you're up to the part of checking for the end of the game and tell me how you are thinking of doing that.
Bill