Forum Moderators: open
Player 1 = X
Player 2 = 0
Use a mechanism such as two manually selected radio buttons to select what player is currently in play
A player clicks on one of the 9 cells in the grid to place their marker
If a cell already has an X or an O then that cell is not playable in any subsequent turns
ple any one know codding or ref site just inform me
thaks
1. You will need to create your radio buttons with some event handlers (note, I actually recommend against using event handlers and instead using event listeners, but I am guessing your teacher hasn't gone over those so I'm going to use handlers instead):
<div><input type="radio" name="player" value="1" onclick="setPlayer(this.value)"> Player 1</div>
<div><input type="radio" name="player" value="2" onclick="setPlayer(this.value)"> Player 2</div>
2. Next, you need to create your event handler function:
// Global variable that holds the current game piece
var piece = "X";
function setPlayer(n) {
// Update the current playing piece based on
// which player was passed in
piece = (n == 1? "X": "O");
}
3. On your game board, you will need to attach onclick event handlers to each cell. When a user clicks a cell, you will need to check to see if there is already a value in that cell, and if not, you will place the current game "piece" in that cell.
If you need more help, feel free to ask. :)