Skip to content
Open
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
19 changes: 16 additions & 3 deletions 02week/ticTacToe.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const rl = readline.createInterface({
output: process.stdout
});
let board = [
[' ', ' ', ' '],
[' ', ' ', ' '],
[' ', ' ', ' ']
array1: [' ', ' ', ' '],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to directly manipulate the game's board variable.

array2: [' ', ' ', ' '],
array3: [' ', ' ', ' ']
];

let playerTurn = 'X';
Expand All @@ -25,14 +25,27 @@ function printBoard() {

function horizontalWin() {
// Your code here
if (array1===[x,x,x]||[o,o,o]){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creative approach but you could check against the playerTurn variable here instead,

This will avoid checking for 'o' wins when playerTurn === x and vice versa,

return "Win!";
}else if (array2===[x,x,x]||[o,o,o]) {
return "Win!"
}else if (array3===[x,x,x]||[o,o,o]) {
return "Win!"
}
}

function verticalWin() {
// Your code here
if (array1[0]===x||o && array2[0]===x||o && array3[0]===x||0){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check against playerTurn here not the literal stings values of o and x

return "Win!"
}
}

function diagonalWin() {
// Your code here
if (array1[0]===x||o && array2[1]===x||o && array3[2]===x||o){
return "Win!"
}
}

function checkForWin() {
Expand Down