Skip to content

Conversation

mac6551
Copy link

@mac6551 mac6551 commented Dec 22, 2021

No description provided.

Copy link

@alope107 alope107 left a comment

Choose a reason for hiding this comment

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

Nice job! State is managed well and callbacks are nicely passed through components. One small thing is that the game allows you to keep on playing even once someone has won and the winner can possibly change. You don't need to implement it, but you might consider what changes your code would need to prevent this. Great work and great display of your knowledge of React!

Comment on lines +33 to +45
const boardCopy = squares.map((row) => {
row.forEach((column) => {
if (column.id === id) {
if (column.value === '') {
if (player === PLAYER_1) {
column.value = PLAYER_1;
} else {
column.value = PLAYER_2;
}
}
}
});
return row;

Choose a reason for hiding this comment

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

Nice use of map!

Comment on lines +47 to +52
setSquares(boardCopy);
if (player === PLAYER_1) {
setPlayer(PLAYER_2);
} else {
setPlayer(PLAYER_1);
}

Choose a reason for hiding this comment

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

Good job updating state.

if (
squares[r][c + 2].value === squares[r + 1][c + 1].value &&
squares[r + 1][c + 1].value === squares[r + 2][c].value &&
squares[r][c].value != ''

Choose a reason for hiding this comment

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

Make sure to use strict inequality !== instead of normal inequality !=.

// all three squares have the same value.
let r = 0;
let c = 0;
let winner = '...';

Choose a reason for hiding this comment

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

Consider having this be a top-level const like PLAYER_1 or PLAYER_2.

Comment on lines +90 to +91
setWinner(winner);
return winner;

Choose a reason for hiding this comment

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

Unclear why some winning lines return the winner and others do not.

</header>
<main>
<Board squares={squares} />
<Board squares={squares} onClickCallback={onSquareClickCallback} />

Choose a reason for hiding this comment

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

Good job passing callback!

checkForWinner();
};

const checkForWinner = () => {

Choose a reason for hiding this comment

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

Consider additional logic that prevents the game from continuing once someone has won.


}
console.log('genereate square components func', squares);
const squareComponents = [].concat(...squares);

Choose a reason for hiding this comment

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

One slightly simpler way to do this is const squareComponents = [...squares];

<Square
value={square.value}
id={square.id}
onClickCallback={onClickCallback}

Choose a reason for hiding this comment

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

Nice job continuing to pass state down.

value={square.value}
id={square.id}
onClickCallback={onClickCallback}
key={square.id}

Choose a reason for hiding this comment

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

Good job remembering key!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants