Open
Conversation
React Tic Tac ToeMajor Learning Goals/Code Review
Functional Requirements
Overall Feedback
Additional FeedbackGreat work! See my inline comments for a couple additional notes. Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
jmaddox19
reviewed
Apr 30, 2020
|
|
||
| const checkRow = (turn) => { | ||
| for (let row = 0; row < 3; row++) { | ||
| if ((squares[row][0].value === turn) && |
There was a problem hiding this comment.
This is minor but this is one of several places where your indentation is just slightly off. I use a VSCode plugin called indent-rainbow to help me catch indentation weirdness like this.
Comment on lines
+77
to
+105
| const checkCol = (turn) => { | ||
| for (let col = 0; col < 3; col++) { | ||
| if ((squares[0][col].value === turn) && | ||
| (squares[1][col].value === turn) && | ||
| (squares[2][col].value === turn)){ | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| const checkDiagonal = (turn) => { | ||
| if ((squares[0][0].value === turn) && | ||
| (squares[1][1].value === turn) && | ||
| (squares[2][2].value === turn)) { | ||
| return true; | ||
| } | ||
| if ((squares[0][2].value === turn) && | ||
| (squares[1][1].value === turn) && | ||
| (squares[2][0].value === turn)){ | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| const checkForWinner = (turn) => { | ||
| if (checkRow(turn) || checkCol(turn) || checkDiagonal(turn)) { | ||
| setWinner(turn) | ||
| } | ||
| } |
There was a problem hiding this comment.
I appreciate that you separated this logic into different functions! It definitely helps make it easier to read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
React Tic Tac Toe
homepage: https://stpatrickschild.github.io/react-tic-tac-toe
1.) How are events / event handlers and
useStateconnected?useStateand can be used to change the state ofComponents. As events happen, the
useStateis used to handle that event.2.) What are two ways to do "dynamic styling" with React? When should they be used?
variable to JSX tag element or to update the component. They should be used when we want to
change the user interface based on the events.
3.) Much like Rails works with the HTTP request->response cycle, React works with the
browser's input->output cycle. Describe React's cycle from receiving user input to
outputting different page content.
Pretty much, when it’s clickedOn, the component sends the response to the app then the app.
Changes the output by whatever the inner method is defined.
CS Fundamentals Questions
1.) What do you think is the BigO complexity of the method you use to compute a winner?
computation.
2.) Consider what happens when React processes a state change from
setState-- it must re-render all of the components that now have different content because of that change.What kind of data structure are the components in, and what sort of algorithms would be appropriate for React's code to "traverse" those components?
Speculate wildly about what the Big-O time complexity of that code might be. |