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

Pokemon game #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Pokemon game #4

wants to merge 3 commits into from

Conversation

zuberman
Copy link

@zuberman zuberman commented Oct 7, 2018

No description provided.



handleSearchSubmit(){
this.setState({
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to pre-calculate the searchList. That way you can set it in state and use it the fetch after without needing the use the callback in setState. Keeps code simpler

}

generateComputerCard(){
let randomPokemonNumber = Math.floor(Math.random() * (800 - 1 + 1)) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

800 - 1 + 1 ?

<div className="card">
{this.props.playerCard.name}<br></br>
<img className="sprite" src={this.props.playerCard.sprites.front_shiny} /><br></br>
Speed: {this.props.playerCard.stats[0].base_stat}<button stat={this.props.playerCard.stats[0].base_stat} name="speed" onClick={ event => this.props.handleClick(this.props.playerCard.stats[0].base_stat, this.props.computerCard.stats[0].base_stat) }>Select</button><br></br>
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this might better generated using a loop rather than code duplication. The only difference between the rows is the label and index. You could create an array of labels, map over them and generate each button using the label from array and its index

{this.props.team[${this.state.currentCardIndex}].name}
{pokemon.stats[${this.state.currentCardIndex}].stat.name}{pokemon.stats[${this.state.currentCardIndex}].base_stat}<button onClick={event => this.handleClick(pokemon)}>Select</button>
</div>
)
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation could be better here

<tbody>
<tr>
<th>{this.props.pokemon.name}</th>
<th>{this.props.pokemon.stats[0].stat.name}</th>
Copy link
Contributor

Choose a reason for hiding this comment

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

Some loops could reduce code duplication here

constructor(){
super();

this.state = {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be removed

<tbody>
<tr>
<th>{pokemon.name}</th>
<th>{pokemon.stats[0].stat.name}</th>
Copy link
Contributor

Choose a reason for hiding this comment

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

using a loop here to generate each line would reduce code duplication

@dmitrigrabov
Copy link
Contributor

Good work. Some code duplication could be removed using loops

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.

None yet

2 participants