diff --git a/main.js b/main.js index 96293a9..7abe624 100644 --- a/main.js +++ b/main.js @@ -33,26 +33,73 @@ const printBoard = () => { } const horizontalWin = () => { - // Your code here to check for horizontal wins + + if(board[0][0] == board[0][1] && board[0][0] == board[0][2]) + { + return true + } + if(board[1][0] == board[1][1] && board[1][0] == board[1][2]) + { + return true + } + if(board[2][0] == board[2][1] && board[2][0] == board[2][2]) + { + return true + } } const verticalWin = () => { - // Your code here to check for vertical wins + if(board[0][0] == board[1][0] && board[0][0] == board[2][0]) + { + return true + } + if(board[0][1] == board[1][1] && board[0][1] == board[2][1]) + { + return true + } + if(board[0][2] == board[1][2] && board[0][2] == board[2][2]) + { + return true + } } const diagonalWin = () => { - // Your code here to check for diagonal wins + if(board[0][0] == board[1][1] && board[0][0] == board[2][2]) + { + return true + } + if(board[0][2] == board[1][1] && board[0][2] == board[2][0]) + { + return true + } } const checkForWin = () => { - // Your code here call each of the check for types of wins + + if(horizontalWin() || verticalWin() || diagonalWin()) + { + return true; + } + else + { + return false + } + } const ticTacToe = (row, column) => { - // Your code here to place a marker on the board - // then check for a win -} + +board[row][column] = playerTurn +if(playerTurn == "X") +{ + playerTurn = "O" +} +else if(playerTurn == "O") +{ + playerTurn = "X" +} +} const getPrompt = () => { printBoard(); console.log("It's Player " + playerTurn + "'s turn."); @@ -64,7 +111,10 @@ const getPrompt = () => { }); } - +// if(checkForWin() == true) +// { +// return playerTurn +// } // Unit Tests // You use them run the command: npm test main.js // to close them ctrl + C