high-card-bootcamp Patrick#59
Open
patrickkok wants to merge 5 commits into
Open
Conversation
… determine winner of round, add tracker for cards left in deck
Flashrob
reviewed
Oct 24, 2023
|
|
||
| render() { | ||
| // You can write JavaScript here, just don't try and set your state! | ||
| const instructions = ( |
There was a problem hiding this comment.
Can we make this a separate component?
| // Give each list element a unique key | ||
| <div key={`${name}${suit}`}> | ||
| {name} of {suit} | ||
| const gameDisplay = ( |
There was a problem hiding this comment.
I feel like this warrants its own component/page as well
| <Button | ||
| className="btn btn-light" | ||
| onClick={ | ||
| this.state.cardsLeft === 0 ? this.refreshPage : this.dealCards |
There was a problem hiding this comment.
Suggested change
| this.state.cardsLeft === 0 ? this.refreshPage : this.dealCards | |
| !this.state.cardsLeft? this.refreshPage : this.dealCards |
0 is falsy
| }; | ||
|
|
||
| refreshPage = () => { | ||
| window.location.reload(); |
There was a problem hiding this comment.
We should avoid hard refreshes like this in a React app. This goes against what React has been developed for :)
|
|
||
| playerOneIsHigher = (list) => { | ||
| const suits = ["Diamonds", "Clubs", "Hearts", "Spades"]; | ||
| if (list.length === 0) { |
There was a problem hiding this comment.
Suggested change
| if (list.length === 0) { | |
| if (!list.length) { |
| console.log(list); | ||
| return null; | ||
| } | ||
| if (list[0].rank === list[1].rank) { |
There was a problem hiding this comment.
Could list[0] or list[1] possibly be undefined? If so, you might face a bug here
Comment on lines
+36
to
+40
| if (suits.indexOf(list[0].suit) > suits.indexOf(list[1].suit)) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Suggested change
| if (suits.indexOf(list[0].suit) > suits.indexOf(list[1].suit)) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| if (suits.indexOf(list[0].suit) > suits.indexOf(list[1].suit)) return true | |
| return false |
Comment on lines
52
to
+66
| this.setState({ | ||
| currCards: newCurrCards, | ||
| cardsLeft: this.state.cardsLeft - 2, | ||
| gameStarted: true, | ||
| playerOneCurrWinner: newPlayerOneCurrWinner, | ||
| }); | ||
| if (newPlayerOneCurrWinner) { | ||
| this.setState({ | ||
| playerOneScore: this.state.playerOneScore + 1, | ||
| }); | ||
| } else { | ||
| this.setState({ | ||
| playerTwoScore: this.state.playerTwoScore + 1, | ||
| }); | ||
| } |
There was a problem hiding this comment.
I think you should consolidate these into a single state update. You could look up how to conditionally set a object property
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.
No description provided.