From 56784ec41782ecea463f0440f123709aaf9d27ec Mon Sep 17 00:00:00 2001 From: JeffAStringer Date: Mon, 14 Dec 2020 18:16:50 -0600 Subject: [PATCH] class work main --- main.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++---- package.json | 2 +- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 96293a9..bc56b4b 100644 --- a/main.js +++ b/main.js @@ -40,17 +40,74 @@ const verticalWin = () => { // Your code here to check for vertical wins } +const horizontalWin = () => { + // Your code here to check for horizontal wins + if((board[0][0] == "X" && board[0][1] == "X" && board[0][2] == "X") || (board[0][0] == "O" && board[0][1] == "O" && board[0][2] == "O")) { + return true + } else if ((board[1][0] == "X" && board[1][1] == "X" && board[1][2] == "X") || (board[1][0] == "O" && board[1][1] == "O" && board[1][2] == "O")) { + return true + } else if ((board[2][0] == "X" && board[2][1] == "X" && board[2][2] == "X") || (board[2][0] == "O" && board[2][1] == "O" && board[2][2] == "O")) { + return true + } else { + return false + } +} + + + +const verticalWin = () => { + // Your code here to check for vertical wins + if((board[0][0] == "X" && board[1][0] == "X" && board[2][0] == "X") || (board[0][0] == "O" && board[1][0] == "O" && board[2][0] == "O")) { + return true + } else if ((board[0][1] == "X" && board[1][1] == "X" && board[2][1] == "X") || (board[0][1] == "O" && board[1][1] == "O" && board[2][1] == "O")) { + return true + } else if ((board[0][2] == "X" && board[1][2] == "X" && board[2][2] == "X") || (board[0][2] == "O" && board[1][2] == "O" && board[2][2] == "O")) { + return true + } else { + return false + } +} + + const diagonalWin = () => { // Your code here to check for diagonal wins + if((board[0][0] == "X" && board[1][1] == "X" && board[2][2] == "X") || (board[0][0] == "O" && board[1][1] == "O" && board[2][2] == "O")) { + return true + } else if ((board[2][0] == "X" && board[1][1] == "X" && board[2][0] == "X") || (board[2][0] == "O" && board[1][1] == "O" && board[2][0] == "O")) { + return true + } else { + return false + } } -const checkForWin = () => { - // Your code here call each of the check for types of wins -} +// const checkForWin = () => { +// if (changeMarker >= i++) +// return true +// } else return {((horizontalWin() || verticalWin() || diagonalWin()) +// console.log(`Player ${playerTurn} won!`) +// return true +// else +// changeMarker() +// } +// } + const checkForWin = () => { + // Your code here call each of the check for types of wins + if(horizontalWin() || verticalWin() || diagonalWin()) { + console.log(`Player ${playerTurn} won!`) + return true + } else { + changeMarker() + } + + } + const ticTacToe = (row, column) => { // Your code here to place a marker on the board // then check for a win + board[row][column] = playerTurn + checkForWin() + } const getPrompt = () => { @@ -104,4 +161,5 @@ if (typeof describe === 'function') { getPrompt(); -} + } +} \ No newline at end of file diff --git a/package.json b/package.json index 33a09c4..de96446 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "eslint": "^3.19.0", "functional-javascript-workshop": "^1.0.6", "htmllint-cli": "github:kevincolten/htmllint-cli", - "http-server": "^0.11.1", + "http-server": "^0.12.3", "javascripting": "^2.6.1", "jsdom": "^11.6.2", "mocha": "^5.0.0",