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

Charles Lee Zhao Yi - Guess The Word #56

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

Conversation

charlesleezhaoyi
Copy link

PR for Guess The Word Assignment. Added exception handling and alerts.

this.state.guessedLetters.pop
),
});
alert("Please enter only one letter at a time.");
Copy link

Choose a reason for hiding this comment

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

Try to avoid alerts. Alerts block the user from interacting from your website, thus it is an anti-pattern to what React is trying to achieve. I suggest rather some red text that shows this validation warning or something along these lines.

Copy link
Author

Choose a reason for hiding this comment

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

That's a great point. I'll look into inline error messaging in future implementations. Thanks Rob!

type="text"
value={this.state.formInput}
onChange={this.handleChange}
></input>
Copy link

Choose a reason for hiding this comment

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

Suggested change
></input>
/>

@@ -43,8 +91,21 @@ class App extends React.Component {
? this.state.guessedLetters.toString()
: "-"}
<h3>Input</h3>
{/* Insert form element here */}
Todo: Insert form element here
<form onSubmit={this.handleSubmit}>
Copy link

Choose a reason for hiding this comment

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

If you are using buttons below for submission, the <form> tag is redundant

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback Rob - will keep in mind for future implementations!

Comment on lines +101 to +106
{this.state.numGuessesLeft > 1 ? (
<button onClick={this.handleSubmit}>Submit</button>
) : (
<button onClick={this.handleSubmit} disabled>
Submit
</button>
Copy link

Choose a reason for hiding this comment

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

Suggested change
{this.state.numGuessesLeft > 1 ? (
<button onClick={this.handleSubmit}>Submit</button>
) : (
<button onClick={this.handleSubmit} disabled>
Submit
</button>
<button onClick={this.handleSubmit} disabled={!this.state.numGuessesLeft}>Submit</button>

Copy link

Choose a reason for hiding this comment

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

Also, should the > 1 not be >= 1?

Copy link
Author

Choose a reason for hiding this comment

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

Great catch - I should have caught this in my implementation. Will improve in logic in future. Thanks Rob!

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