Tell us what’s happening:
I pass the challenge but I have a question.
I pass the challenge when I use this.state.userAge
but the challenge was not passing when I used this.state.input
So What are the differences between them ?
const inputStyle = {
width: 235,
margin: 5
};
class CheckUserAge extends React.Component {
constructor(props) {
super(props);
// Change code below this line
this.state = {
input: "",
userAge: ""
};
// Change code above this line
this.submit = this.submit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.setState({
input: e.target.value,
userAge: ""
});
}
submit() {
this.setState((state) => ({
userAge: state.input
}));
}
render() {
const buttonOne = <button onClick={this.submit}>Submit</button>;
const buttonTwo = <button>You May Enter</button>;
const buttonThree = <button>You Shall Not Pass</button>;
return (
<div>
<h3>Enter Your Age to Continue</h3>
<input
style={inputStyle}
type="number"
value={this.state.input}
onChange={this.handleChange}
/>
<br />
{/* Change code below this line */}
{this.state.userAge === ""
? buttonOne
: this.state.userAge < 18
? buttonThree
: buttonTwo}
{/* Change code above this line */}
</div>
);
}
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:90.0) Gecko/20100101 Firefox/90.0
Challenge: Use a Ternary Expression for Conditional Rendering
Link to the challenge: