Skip to content

Lina and Noor#10

Open
hn4ever wants to merge 11 commits intoAda-C14:masterfrom
lina5147:master
Open

Lina and Noor#10
hn4ever wants to merge 11 commits intoAda-C14:masterfrom
lina5147:master

Conversation

@hn4ever
Copy link

@hn4ever hn4ever commented Dec 31, 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 an event happens it will call our event handler function and This function will help update the State.
What are two ways to do "dynamic styling" with React? When should they be used? One of the ways is using the inline CSS style attribute and the other way is using CSS as a stylesheet and setting it to the className attribute. In JSX we would utilize the brackets {} to pass the code to generate view data.
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. In React, user input is received by events which triggers event handler function and that will update and change page contents. As a response it will render the new page and goes to this cycle again when the user does another event.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? For this game we know that the length of squares will always be the same, therefore time complexity is O(1). The space complexity is O(1) as there is no new allocation of memory.
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.
The data structure is possibly a tree that starts from the top level (app component) and then it traverses into next component (the board). The last level is the squares. For time complexity, we think it would be O(n * components big O) where n is the times the app is rendered.

Copy link

@kaidamasaki kaidamasaki left a comment

Choose a reason for hiding this comment

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

For TicTacToe we reviewed test results, the checkForWinner function, and onClickCallback function.

Good work implementing a React project using state and callback functions!

Comment on lines +81 to +96
for(let i = 0; i < squares.length; i ++){
if (squares[i][0].value === squares[i][1].value && squares[i][1].value === squares[i][2].value && squares[i][0].value !== ''){
setWinner(squares[i][0].value)
}
else if (squares[0][i].value === squares[1][i].value && squares[1][i].value === squares[2][i].value && squares[1][i].value !==''){
setWinner(squares[0][i].value)
}
}
// diaognal
if(squares[0][0].value === squares[1][1].value && squares[1][1].value === squares[2][2].value && squares[1][1] !== ''){
setWinner(squares[0][0].value)
} else if(squares[2][0].value === squares[1][1].value && squares[1][1].value === squares[0][2].value && squares[1][1] !== ''){
setWinner(squares[2][0].value)
}

}

Choose a reason for hiding this comment

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

Nice job with this loop! Getting it right is tricky. 😃

Copy link
Author

Choose a reason for hiding this comment

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

Thank you Kaida

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