Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cedar - Lizet and Kristin #61

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Cedar - Lizet and Kristin #61

wants to merge 14 commits into from

Conversation

Kbhlee2121
Copy link

No description provided.

Copy link

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

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

Great work on this complex React project. Your code is clear and logical. You've clearly met the learning goals around event handling, managing state, and working with 2D arrays. Nice work!

// When it is clicked on.
// Then pass it into the squares as a callback
const setSquareValue = (id) => {
const newSquares = [...squares];

Choose a reason for hiding this comment

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

Nice use of destructuring

for (let row of newSquares) {
for (let square of row) {
if (square.id === id) {
if (square.value === '') {

Choose a reason for hiding this comment

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

Great check that the square is empty!

Comment on lines +38 to +39
if (square.id === id) {
if (square.value === '') {

Choose a reason for hiding this comment

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

Consider combing with a compound conditional

Comment on lines +41 to +45
if (currentPlayer === PLAYER_1) {
setCurrentPlayer(PLAYER_2);
} else {
setCurrentPlayer(PLAYER_1);
}

Choose a reason for hiding this comment

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

This could be a nice place to refactor with a ternary

const checkForWinner = (squares) => {
let newWinner;
let i = 0;
while (i < 3) {

Choose a reason for hiding this comment

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

A while loop works, but can be easy to introduce a bug. Consider using a for loop if you're looping a set number of times.

}
}
}
checkForWinner(newSquares);

Choose a reason for hiding this comment

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

Note that this function is called even after there has been a winner, so a player can continue playing after the other player wins. Consider how you can put in a check to update the winner only if there isn't a current winner.

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