Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scissors - Araceli #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

aracelim1234
Copy link

No description provided.

// }
// }, [result]);

const changePlayers = () => {

Choose a reason for hiding this comment

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

Great helper function!

changePlayers();
checkForWinner();

};


const checkForWinner = () => {

Choose a reason for hiding this comment

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

All of the logic in here works! With some minor changes it can be updated to update the UI (and pass the tests):

  1. set a variable (ex: let winner = null) at the top of the function.
  2. If a winner is ever found, set winner equal to the player that has won (ex, on line 78 winner = squares[0][index].value).
  3. At the end of the function save the winner in state.
  4. Create a function that checks the winner state variable and returns a string that contains either "Winner is [winner]" or "The winner is..." and call the function on line 123 inside the

    tags.

The last piece is to add a check at the top of markSquares that returns if a winner has been found so that squares can not continue to be marked.

// possibly try to use a counter?

};


const resetGame = () => {

Choose a reason for hiding this comment

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

👍

Comment on lines +75 to +79
if (squares[0][index].value===squares[1][index].value &&
squares[1][index].value===squares[2][index].value &&
squares[0][index].value!=='') {
alert(`Game Finished! Winning Player: ${player}`);
resetGame();

Choose a reason for hiding this comment

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

This chunk of code is repeated for rows and diagonals, the only changes are which points are being checked. I recommend thinking about creating a helper function that does this comparison function to improve readability.

@jbieniosek
Copy link

Great work on this project! All of the logic for checking for a win works very well. Nice work with the reset extension! This project is green.

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