Skip to content

Cedar - Lizet and Kristin#61

Open
Kbhlee2121 wants to merge 14 commits intoAda-C16:mainfrom
Kbhlee2121:main
Open

Cedar - Lizet and Kristin#61
Kbhlee2121 wants to merge 14 commits intoAda-C16:mainfrom
Kbhlee2121:main

Conversation

@Kbhlee2121
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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!

Comment thread src/App.js
// When it is clicked on.
// Then pass it into the squares as a callback
const setSquareValue = (id) => {
const newSquares = [...squares];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice use of destructuring

Comment thread src/App.js
for (let row of newSquares) {
for (let square of row) {
if (square.id === id) {
if (square.value === '') {
Copy link
Copy Markdown

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 thread src/App.js
Comment on lines +38 to +39
if (square.id === id) {
if (square.value === '') {
Copy link
Copy Markdown

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 thread src/App.js
Comment on lines +41 to +45
if (currentPlayer === PLAYER_1) {
setCurrentPlayer(PLAYER_2);
} else {
setCurrentPlayer(PLAYER_1);
}
Copy link
Copy Markdown

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

Comment thread src/App.js
const checkForWinner = (squares) => {
let newWinner;
let i = 0;
while (i < 3) {
Copy link
Copy Markdown

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.

Comment thread src/App.js
}
}
}
checkForWinner(newSquares);
Copy link
Copy Markdown

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