Skip to content

high-card-bootcamp Patrick#59

Open
patrickkok wants to merge 5 commits into
rocketacademy:mainfrom
patrickkok:main
Open

high-card-bootcamp Patrick#59
patrickkok wants to merge 5 commits into
rocketacademy:mainfrom
patrickkok:main

Conversation

@patrickkok
Copy link
Copy Markdown

No description provided.

Comment thread src/App.js

render() {
// You can write JavaScript here, just don't try and set your state!
const instructions = (
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we make this a separate component?

Comment thread src/App.js
// Give each list element a unique key
<div key={`${name}${suit}`}>
{name} of {suit}
const gameDisplay = (
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I feel like this warrants its own component/page as well

Comment thread src/App.js
<Button
className="btn btn-light"
onClick={
this.state.cardsLeft === 0 ? this.refreshPage : this.dealCards
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
this.state.cardsLeft === 0 ? this.refreshPage : this.dealCards
!this.state.cardsLeft? this.refreshPage : this.dealCards

0 is falsy

Comment thread src/App.js
};

refreshPage = () => {
window.location.reload();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should avoid hard refreshes like this in a React app. This goes against what React has been developed for :)

Comment thread src/App.js

playerOneIsHigher = (list) => {
const suits = ["Diamonds", "Clubs", "Hearts", "Spades"];
if (list.length === 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (list.length === 0) {
if (!list.length) {

Comment thread src/App.js
console.log(list);
return null;
}
if (list[0].rank === list[1].rank) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could list[0] or list[1] possibly be undefined? If so, you might face a bug here

Comment thread src/App.js
Comment on lines +36 to +40
if (suits.indexOf(list[0].suit) > suits.indexOf(list[1].suit)) {
return true;
} else {
return false;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 thread src/App.js
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,
});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you should consolidate these into a single state update. You could look up how to conditionally set a object property

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