Skip to content

Cedar - Kit/Laurel#59

Open
KitSutliff wants to merge 5 commits intoAda-C16:mainfrom
KitSutliff:main
Open

Cedar - Kit/Laurel#59
KitSutliff wants to merge 5 commits intoAda-C16:mainfrom
KitSutliff:main

Conversation

@KitSutliff
Copy link
Copy Markdown

tic-tac-toe submission

Copy link
Copy Markdown

@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! You've got some great logic here. There are some bugs that can arise after the game has been won, but the overall functionality is good! This is a nice showcase of your knowledge of React!

Comment thread src/App.js
Comment on lines +30 to +32
const [squares, setSquares] = useState(generateSquares());
const[winner, setWinner] = useState(null);
const [currentPlayer, setCurrentPlayer] = useState(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.

Nice use of state!

Comment thread src/App.js
Comment on lines +34 to +35
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.

Consider using a for loop here instead.

Comment thread src/App.js
Comment on lines +76 to +88
let newBoard = squares.map((square)=>{
for (let property of square){
if (property.id === id && property.value === ''){
if (currentPlayer === PLAYER_1){
property.value = PLAYER_1;

} else if (currentPlayer === PLAYER_2){
property.value = PLAYER_2;
}
}
}
return square;
});
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 map!

Comment thread src/App.js
header = <h2>Winner is {winner}</h2>;
} else {
header = <h2>The Current Player is {currentPlayer}</h2>;
boardCallback = onClickCallback;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because this callback is only set if there's not a winner weird bugs can arise. For example, if someone wins the game, and then a square is clicked again, your whole React app will crash (not even the reset button will work anymore). Consider ways you can resolve this by always passing a callback but having it do different things if the game is won or not.

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>
{header}
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 state!

Comment thread src/components/Board.js
<Square value={square.value}
id={square.id}
onClickCallback={onClickCallback}
key={square.id}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job remembering to use key!

Comment thread src/components/Board.js

}

const singleSquares = [].concat(...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.

This can be done slightly simpler with const singleSquares = [...squares];

Comment thread src/components/Square.js
// Component to alert a parent
// component when it's clicked on.

const hardestButtonToButton = () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fun function name 😛

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