Skip to content

Commit 41122ab

Browse files
committed
create gameOver function
1 parent 9ca7ed1 commit 41122ab

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

public/js/script.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ function checkWin(board, player) {
6565
}
6666
}
6767
return gameWon;
68-
}
68+
}
69+
70+
//create highlights all cells that make up a victory and prevents the user from entering any more boxes
71+
function gameOver(gameWon) {
72+
for (let index of winCombos[gameWon.index]) {
73+
document.getElementById(index).style.backgroundColor =
74+
gameWon.player == oPlayer ? "blue" : "red";
75+
}
76+
for (var i = 0; i < cells.length; i++) {
77+
cells[i].removeEventListener('click', turnClick, false);
78+
}
79+
}

0 commit comments

Comments
 (0)