forked from wdi-sg/tictactoe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (30 loc) · 1.01 KB
/
Copy pathscript.js
File metadata and controls
34 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const gameBoard = document.createElement('div');
gameBoard.id = 'game-board';
//append gameBoard to body
document.body.appendChild(gameBoard);
var currentPlayer = 'Player 1';
const checkWinner = () => {
const gameTiles = document.querySelectorAll('.game-tile');
const matrix = [];
const rows = [];
const cols = [];
}
const playerMove = event => {
const tile = event.target;
tile.dataset.symbol = currentPlayer === 'Player 1' ? 'o' : 'x';
tile.innerHTML = currentPlayer === 'Player 1' ? 'o' : 'x';
// switch player
if (currentPlayer === 'Player 1') {
currentPlayer = 'Player 2';
} else {
currentPlayer = 'Player 1';
}
return checkWinner();
};
for (let index = 0; index < 9; index++) {
let gameTile = document.createElement('div');
gameTile.classList.add('game-tile', `game-tile-${index}`); // ` template literal ${-lets you put variable here-}
gameTile.addEventListener('click', playerMove);
gameBoard.appendChild(gameTile);
console.log(gameTile);
}