Skip to content

Commit d5fa8f2

Browse files
committed
create turnClick function
1 parent 1a9f958 commit d5fa8f2

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

public/js/script.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11

2+
var origBoard;
3+
const oPlayer = 'O';
24
const cells = document.querySelectorAll('.cell');
35
startGame();
46

57
function startGame() {
68
document.querySelector(".endgame").style.display = "none";
79
origBoard = Array.from(Array(9).keys());
10+
console.log(origBoard);
811
for (var i = 0; i < cells.length; i++) {
9-
cells[i].innerText = '';
12+
cells[i].innerText = ''; //clear
1013
cells[i].style.removeProperty('background-color');
14+
//add a event process vào click mouse event
1115
cells[i].addEventListener('click', turnClick, false);
1216
}
1317
}
18+
19+
20+
function turnClick(square) {
21+
// // write down the ID of any cell clicked
22+
console.log(square.target.id)
23+
24+
// pass in the ID that clicking
25+
turn(square.target.id,oPlayer)
26+
}

0 commit comments

Comments
 (0)