-
Notifications
You must be signed in to change notification settings - Fork 80
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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]; |
There was a problem hiding this comment.
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 === '') { |
There was a problem hiding this comment.
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!
if (square.id === id) { | ||
if (square.value === '') { |
There was a problem hiding this comment.
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
if (currentPlayer === PLAYER_1) { | ||
setCurrentPlayer(PLAYER_2); | ||
} else { | ||
setCurrentPlayer(PLAYER_1); | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
No description provided.