summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTinWoodman92 <chrhodgden@gmail.com>2024-01-15 17:51:49 -0600
committerTinWoodman92 <chrhodgden@gmail.com>2024-01-15 17:51:49 -0600
commit4f41c8fce448933e88965833feff0fb3faab79b5 (patch)
tree6586d04a694a98bde4efe11c3e82163ec7a97853
parent609cde41abfbae145a4ce0aa0aa8c83f6ab123ec (diff)
color victory squares on vitory.
-rw-r--r--app.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/app.js b/app.js
index 0a21da8..158168b 100644
--- a/app.js
+++ b/app.js
@@ -20,23 +20,27 @@ const checkVictory = function() {
checkSum = checkRow.reduce((acc, value) => acc + value, 0);
if (checkSum == 3) {
victory = true;
- board.victory_row = row;
+ this.victoryRow = row;
};
checkRow = this.oBoard.filter((_, index) => row.includes(index));
checkSum = checkRow.reduce((acc, value) => acc + value, 0);
if (checkSum == 3) {
victory = true;
- board.victory_row = row;
+ this.victoryRow = row;
};
});
if (victory) {
- board.victor = board.turn;
+ this.victor = this.turn;
+ this.colorVictoryRow();
};
return(victory);
};
const colorVictoryRow = function () {
-
+ this.victoryRow.forEach(squareIndex => {
+ this.squares[squareIndex].style.color = 'var(--background-color)';
+ this.squares[squareIndex].style.backgroundColor = 'var(--foreground-color)';
+ });
};
const squareClick = function() {
@@ -77,6 +81,7 @@ const initBoard = function(board) {
//diagonals
[0, 4, 8], [2, 4, 6]
];
+ board.colorVictoryRow = colorVictoryRow;
};
const board = document.getElementById('board');