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
60 changes: 0 additions & 60 deletions 01week/rockPaperScissors.js

This file was deleted.

60 changes: 50 additions & 10 deletions 03week/ticTacToe.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,66 @@ function printBoard() {
console.log('2 ' + board[2].join(' | '));
}

function horizontalWin() {
// Your code here
// Check for winning horizontal with if
// 00 01 02
// 10 11 12
// 20 21 22
const horizontalWin = () => {
if ((board[0][0] === board[0][1] && board[0][1] === board[0][2]) || (board[1][0] === board[1][1] && board[1][1] === board[1][2]) || (board[2][0] === board[2][1] &&
Copy link

Choose a reason for hiding this comment

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

Yes! Yes yes! You got the short way to reference three cells. Nice work! I mean, SOLID work!

board[2][1] === board[2][2])) {
return true;
}
}

function verticalWin() {
// Your code here
//Check for winning vertical with if
//00 10 20
//01 11 21
//02 12 22
const verticalWin = () => {
if ((board[0][0] === board[1][0] && board[1][0] === board[2][0]) || (board[0][1] === board[1][1] && board[1][1] === board[2][1]) || (board[0][2] === board[1][2] &&
board[1][2] === board[2][2])) {
return true;
}
}

function diagonalWin() {
// Your code here
// Check for winning diagonalWin with if
// 00 11 22
// 02 11 20
const diagonalWin = () => {
if (board[0][0] === board[1][1] && board[1][1] === board[2][2] || (board[0][2] === board[1][1] && board[1][1] === board[2][0])) {
return true;
}
}

function checkForWin() {
// Your code here
// Got help from eddy, I do not completely understand yet
const checkForWin = () => {
// if (horizontalWin() || verticalWin() || diagonalWin()) {
Copy link

Choose a reason for hiding this comment

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

You can do it! This logic is correct, keep going! Just ignore the turncount thing, and if you look at the tests below, they expect checkForWin() to return either true or false.

// console.log(`Player ${playerTurn} Wins!`);
// } else if (turnCount === 9) {
// console.log("It's a tie!")
// } else {
// return false;
//}

}

// Got help from eddy, I do not completely understand yet
function ticTacToe(row, column) {
// Your code here
//
// if (playerTurn === 'X') {
// playerTurn = 'O';
// } else {
// playerTurn = 'X';
// }
// if (board[row][column] === ' ') {
// board[row].splice(column, 1, playerTurn);
Copy link

Choose a reason for hiding this comment

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

Instead of using unnecessary methods, set that value = to playerTurn.

// }
// return false;

}



function getPrompt() {
printBoard();
console.log("It's Player " + playerTurn + "'s turn.");
Expand All @@ -68,7 +108,7 @@ if (typeof describe === 'function') {
});
it('should alternate between players', () => {
ticTacToe(0, 0);
assert.deepEqual(board, [ ['O', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]);
assert.deepEqual(board, [ ['O', '', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]);
Copy link

Choose a reason for hiding this comment

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

Put the space back! The tests need it! (In board[0][1], I think you accidentally took it out).

});
it('should check for vertical wins', () => {
board = [ [' ', 'X', ' '], [' ', 'X', ' '], [' ', 'X', ' '] ];
Expand Down