The code below is rendering button three when previewed. I couldn't locate the error that makes it render buttonThree instead of buttonOne. Can someone help?

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

const inputStyle = {
width: 235,
margin: 5
};

class CheckUserAge extends React.Component {
constructor(props) {
  super(props);
  // Change code below this line
this.state={
userAge:" ",
input:" "
};
  // 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 ? buttonTwo : buttonThree }
      

      {/* Change code above this line */}
    </div>
  );
}
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 10; TECNO B1g) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.96 Mobile Safari/537.36

Challenge: Use a Ternary Expression for Conditional Rendering

Link to the challenge:

You wrote this

so this is always false

Thanks, it solves the problem.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.