Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 62 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -104,4 +161,5 @@ if (typeof describe === 'function') {

getPrompt();

}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down