-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (30 loc) · 762 Bytes
/
script.js
File metadata and controls
35 lines (30 loc) · 762 Bytes
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
35
let origBoard;
let huPlayer = "x";
let aiPlayer = "O";
const winCombos = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
];
const cells = document.querySelectorAll(".cell");
startGame();
function startGame() {
document.querySelector(".endgame").style.display = "none";
origBoard = Array.from(Array(9).keys());
for (let i = 0; i < cells.length; i++) {
cells[i].innerText = "";
cells[i].style.removeProperty("background-color");
cells[i].addEventListener("click", turnClick, false);
}};
function turnClick(square){
turn(square.target.id, huPlayer)
};
function turn(squareId, player){
origBoard[squareId] = player;
document.getElementById(squareId).innerText = player;
}