Skip to content

Scissors - Hena#49

Open
hena-lee wants to merge 4 commits into
Ada-C15:masterfrom
hena-lee:master
Open

Scissors - Hena#49
hena-lee wants to merge 4 commits into
Ada-C15:masterfrom
hena-lee:master

Conversation

@hena-lee
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.

Good work on this project involving state and event handling with nested components. You have met the learning goals around Handling user events, Updating the UI, and Updating the state of the game. There was one small bug in your winner functionality that I have pointed out. Please let me know if you have any questions.

Comment thread src/App.js
<h1>React Tic Tac Toe</h1>
<h2>The winner is ... -- Fill in for wave 3 </h2>
<button>Reset Game</button>
<h2>The winner is ...{winner}</h2>
Copy link
Copy Markdown

@beccaelenzil beccaelenzil Jun 30, 2021

Choose a reason for hiding this comment

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

The bug is here! The test is looking for the specific text Winner is x and it gets The winner is ... x.

Comment thread src/App.js
})

// a bug exists here somewhere or elsewhere
if (entireBoard[0] === entireBoard[1] && entireBoard[0] === entireBoard[2]){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Flattening the array and using the flatten array to check for winners certainly works. Considering adding comments to make it clear where you are checking for rows, columns, and diagonals. It looks like you missed columns. Consider also using an algorithm based on the squares 2D array so that you don't have to do the extra work of flattening.

Comment thread src/App.js


const markBoard = (id) => {
squares.forEach((row)=>{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When using React useState hook, we shouldn't directly modify squares. Instead, we can make a copy of squares. One option for this which makes a copy of the outer array is using the spread operator const newSquares = [...squares]. Then we assign our new value to our newSquares and call setSquares(newSquares). This is because of how the useState hook works -- calling setSquares triggers the re-render. In this code, it ends up working because we also call setPlayer which triggers a re-render.

Comment thread src/App.js
if (square.id === id && square.value === ''){
if (player === PLAYER_1) {
setPlayer(PLAYER_2);
square.value = 'x'
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 setting the value to the value of PLAYER_2 to help avoid introducing bugs.

Suggested change
square.value = 'x'
square.value = PLAYER_2

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.

2 participants