diff --git a/src/components/TicTacToe.jsx b/src/components/TicTacToe.jsx
index 44afe50..7ede753 100644
--- a/src/components/TicTacToe.jsx
+++ b/src/components/TicTacToe.jsx
@@ -61,15 +61,13 @@ export default function TicTacToe({ boardWidth, boardHeight }) {
* sets currentTurn to "X" and sets winner to null
*/
function resetGame() {
- // Clear the Tic-Tac-Toe board
- // Hint: Use the generateEmptyBoard function!
+ setBoard(initialBoard);
- // Set currentTurn to "X"
+ setCurrentTurn("X");
- // Set winner to null
-
+ setWinner(null);
}
@@ -230,7 +228,7 @@ export default function TicTacToe({ boardWidth, boardHeight }) {
diff --git a/src/functions/checkForWinner.js b/src/functions/checkForWinner.js
index 2b713c3..b653e5f 100644
--- a/src/functions/checkForWinner.js
+++ b/src/functions/checkForWinner.js
@@ -52,9 +52,55 @@ export default function checkForWinner(board) {
}
}
- // Add additional winner checking logic here...
- // Under what conditions can someone win?
+ for (let column = 0; column < board.length; column++) {
+ let firstCell = board[0][column];
+ if (firstCell === null) {
+ continue;
+ }
+
+ let isWinningColumn = true;
+ for (let row = 1; row < board.length; row++) {
+ if (board[row][column] !== firstCell) {
+ isWinningColumn = false;
+ break;
+ }
+ }
+
+ if (isWinningColumn) {
+ return firstCell;
+ }
+ }
+
+ let firstDiagonalCell = board[0][0];
+ if (firstDiagonalCell !== null) {
+ let isWinningDiagonal = true;
+ for (let i = 1; i < board.length; i++) {
+ if (board[i][i] !== firstDiagonalCell) {
+ isWinningDiagonal = false;
+ break;
+ }
+ }
+
+ if (isWinningDiagonal) {
+ return firstDiagonalCell;
+ }
+ }
+
+ let secondDiagonalCell = board[0][board.length - 1];
+ if (secondDiagonalCell !== null) {
+ let isWinningDiagonal = true;
+ for (let i = 1; i < board.length; i++) {
+ if (board[i][board.length - 1 - i] !== secondDiagonalCell) {
+ isWinningDiagonal = false;
+ break;
+ }
+ }
+
+ if (isWinningDiagonal) {
+ return secondDiagonalCell;
+ }
+ }
// Return null if no winners
return null;
diff --git a/src/pages/HelloPage.jsx b/src/pages/HelloPage.jsx
index f9976da..eadef83 100644
--- a/src/pages/HelloPage.jsx
+++ b/src/pages/HelloPage.jsx
@@ -45,7 +45,7 @@ export default function HelloPage() {
* Can you find where the PageTitle component declaration is?
*/
}
-