Help with Tic Tac Toe 2player version

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: kgudger, bfinio, Moderators

Locked
peachyuu
Posts: 3
Joined: Wed Mar 19, 2014 1:10 pm
Occupation: Student:12th grade
Project Question: Computer Science
Project Due Date: May 3rd 2014
Project Status: Not applicable

Help with Tic Tac Toe 2player version

Post by peachyuu »

Hello,I'm currently working on the tic tac toe project from https://www.sciencebuddies.org/science- ... background and I need help. I am working on the 2 player version. I have the sqaures set but when I click on them nothing happens. Here are my codes:

Code: Select all

<!DOCTYPE html>
<html>
<head>
<title>Tic Tac Toe!</title> 
</head>
<h1>Tic Tac Toe 2 player version</h1>




<SCRIPT TYPE="TEXT/JAVASCRIPT">

var xTurn = true;

function squareclicked(square)
 // squareclicked is a function that is called whenever a button is clicked.
 {
    var status = document.getElementById('status');
    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('That square has already been played.');
  }
function newgame()
 {
    var status = document.getElementById('status');

    xTurn = true;
    status.innerHTML = 'X\'s turn';

    for(var x = 0; x < x++)    {
       for(var y = 0; y < y++)       {
          document.getElementById(x + '_' + y).value = ' ';
       }
    }
 }
</SCRIPT>
<body>
<P align="center">

 <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)";>


 <BR><BR>

<INPUT TYPE="BUTTON" ID="NEWGAME" VALUE="New Game" ONCLICK="newgame();">
<P ID="status" align="center"

<P ID="status">X's turn</P>
Locked

Return to “Grades 9-12: Math and Computer Science”