Tic Tac Toe Syntax error
Posted: Thu Apr 18, 2013 8:01 pm
Hi. I am using dream weaver, I don't exactly know how to code. I kinda bit off more then i can chew. I only took a few lessons off of codecademy.com I'm stuck here, and don't know exactly what to do. I dont get the x+ __ + y thing at all. I have all the layout but there is no X or O when i click on the buttons.
Code: Select all
<!DOCTYPE html>
<head>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
function newgame(){
var status = document.getElementById('status');
var xTurn=true;
status.innerHTML = 'X\'s turn';
for (var x=0; x < 14;x++) {
for (var x=0; x< 14;x++) {
document.getElementById(x + '_' + y).value = ' ';
}
}
}
function squareclicked(square)
{
var value = square.value;
if (value != 'X' && value!= 'O')
{
if(xTurn)
{
square.value=('X');
xTurn = false;
status.innerHTML = 'O\'s turn';
}
else
{
square.value='O';
xTurn = true;
status.innerHTML = 'X\'s turn';
}
}
else
alert('Stop fooling around. Pick another square.');
}
var gameOver = false;
var numMoves = 0;
function checkWin()
{
var status = document.getElementById('status');
var val0;
var val1;
var val2;
for(var y = 0; y<15; y++)
{
val0 = document.getElementById('0_'+y).value;
val1 = document.getElementById('1_'+y).value;
val2 = document.getElementById('2_'+y).value;
if(val0 == 'X' && val1 == 'X' && val2 == 'X')
{
status.innerHTML = "X WINS!";
return true;
}
else if(val0 == 'O' && val1 == 'O' && val2 == 'O')
{
status.innerHTML = "O WINS!";
return true;
}
}
}
for(var x = 0; x<15; x++)
{
val0 = document.getElementById(x+'_0').value;
val1 = document.getElementById(x+'_1').value;
val2 = document.getElementById(x+'_2').value;
if(val0 == 'X' && val1 == 'X' && val2 == 'X')
{
status.innerHTML = "X WINS!";
\\line 76
return true;
}
else if(val0 == 'O' && val1 == 'O' && val2 == 'O')
{
status.innerHTML = "O WINS!";
return true;
}
}
}
<title>Tic Tac Toe Experiment
</title>
</SCRIPT>
</head>
<h1>Tic Tac Toe</h1>
<body>
<p>
<INPUT TYPE="BUTTON" ID="0_0" VALUE=" "ONCLICK=;"squareclicked(this);">
<INPUT TYPE="BUTTON" ID="1_0" VALUE=" "ONCLICK=;"squareclicked(this);">
<INPUT TYPE="BUTTON" ID="2_0" VALUE=" "ONCLICK=;"squareclicked(this);">
<BR>
<INPUT TYPE="BUTTON" ID="0_1" VALUE=" "ONCLICK=;"squareclicked(this);">
<INPUT TYPE="BUTTON" ID="1_1" VALUE=" "ONCLICK=;"squareclicked(this);">
<INPUT TYPE="BUTTON" ID="2_1" VALUE=" "ONCLICK=;"squareclicked(this);">
<BR>
<INPUT TYPE="BUTTON" ID="0_2" VALUE=" "ONCLICK=;"squareclicked(this);">
<INPUT TYPE="BUTTON" ID="1_2" VALUE=" "ONCLICK=;"squareclicked(this);">
<INPUT TYPE="BUTTON" ID="2_2" VALUE=" "ONCLICK=;"squareclicked(this);">
<h1>
</h1>
<BR>
<input type="BUTTON" id="NEWGAME" value="New Game" onClick="newgame();">
</p>
</body>
<P ID="status">X's turn</P>
</html>