Skip to content

Commit 0e172f7

Browse files
committed
create checkTie function
1 parent d74d962 commit 0e172f7

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

public/js/script.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function gameOver(gameWon) {
8484
}
8585
}
8686

87+
function declareWinner(whoWin) {
88+
document.querySelector(".endgame").style.display = "block";
89+
document.querySelector(".endgame .text").innerText = whoWin;
90+
}
91+
8792
function emptySquares() {
8893
//filter every element from the board array
8994
return origBoard.filter(s => typeof s == 'number');
@@ -92,3 +97,15 @@ function emptySquares() {
9297
function bestSpot() { //Find all blank cells and get first element from blank cell. So the AI will always play the first slot
9398
return emptySquares()[0];
9499
}
100+
101+
function checkTie() {
102+
if (emptySquares().length == 0) {
103+
for (var i = 0; i < cells.length; i++) {
104+
cells[i].style.backgroundColor = "pink";
105+
cells[i].removeEventListener('click', turnClick, false);
106+
}
107+
declareWinner("Tie Game!")
108+
return true;
109+
}
110+
return false;
111+
}

0 commit comments

Comments
 (0)