Skip to content

Conversation

@vwhwang
Copy link

@vwhwang vwhwang commented Apr 20, 2020

React Tic Tac Toe

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Prompt Response
How are events / event handlers and useState connected? when clicked the state would change.
What are two ways to do "dynamic styling" with React? When should they be used? inline styles / render method.
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. mounting/updating/unmounting.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? O(n)
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.
O(n), components, objects.

@jmaddox19
Copy link

React Tic Tac Toe

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
Demonstrates proper JavaScript coding style. ✔️
Correctly passes props to child components. ✔️
Correctly passes callback functions to child components and calls them to respond to user events.) ✔️
Maintains the status of the game in state. ✔️
Practices git with at least 6 small commits and meaningful commit messages ✔️
Uses existing stylesheets to render components ✔️

Functional Requirements

Functional Requirement yes/no
The Square component renders properly and executes the callback on a click event. ✔️
The Board component renders a collection of squares ✔️
The App component renders a board and uses state to maintain the status of the game. ✔️
Utilizes callbacks to UI events to update state ✔️

Overall Feedback

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 5+ in Code Review && 3+ in Functional Requirements ✔️
Yellow (Approaches Standards) 4+ in Code Review && 2+ in Functional Requirements, or the instructor judges that this project needs special attention
Red (Not at Standard) 0-3 in Code Review or 0,1 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging, or the instructor judges that this project needs special attention

Great work!

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Elegant/Clever
Descriptive/Readable
Concise
Logical/Organized

Comment on lines +76 to +95
if(squares[0][0].value===squares[0][1].value && squares[0][1].value===squares[0][2].value && squares[0][0].value !==""){
setWinner(true);
showWinner("The winner is " + squares[0][0].value);

}
else if
(squares[1][0].value===squares[1][1].value && squares[1][1].value===squares[1][2].value && squares[1][0].value !==""){
setWinner(true);
showWinner("The winner is " + squares[1][0].value);
}
else if
(squares[2][0].value===squares[2][1].value && squares[2][1].value===squares[2][2].value && squares[2][0].value !==""){
setWinner(true);
showWinner("The winner is " + squares[2][0].value);
}
else if
(squares[0][0].value===squares[1][0].value && squares[1][0].value===squares[2][0].value && squares[0][0].value !==""){
setWinner(true);
showWinner("The winner is " + squares[0][0].value);
}

Choose a reason for hiding this comment

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

This certainly works but could be "DRYed" up by setting this up in a loop format.

Comment on lines +10 to +18
[<Square id={squares[0][0].id} value={squares[0][0].value} onClickCallback={onClickCallback} />,
<Square id={squares[0][1].id} value={squares[0][1].value} onClickCallback={onClickCallback} />,
<Square id={squares[0][2].id} value={squares[0][2].value} onClickCallback={onClickCallback} />,
<Square id={squares[1][0].id} value={squares[1][0].value} onClickCallback={onClickCallback} />,
<Square id={squares[1][1].id} value={squares[1][1].value} onClickCallback={onClickCallback} />,
<Square id={squares[1][2].id} value={squares[1][2].value} onClickCallback={onClickCallback} />,
<Square id={squares[2][0].id} value={squares[2][0].value} onClickCallback={onClickCallback} />,
<Square id={squares[2][1].id} value={squares[2][1].value} onClickCallback={onClickCallback} />,
<Square id={squares[2][2].id} value={squares[2][2].value} onClickCallback={onClickCallback} />]

Choose a reason for hiding this comment

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

This could also be DRYed up with a loop.

// When it is clicked on.
// Then pass it into the squares as a callback

const changeSquare = (changedSquare)=>{

Choose a reason for hiding this comment

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

The way the program is written, if a play accidentally clicks a space that has already been claimed, they lose their turn. A check could be added to this function to address that.

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