Tell us what’s happening:
I’m having trouble understanding the instructions.
Specifically, can anyone clarify what the following means:
"Once the component is rendering information to the page, users should have a way to interact with it. "
What does it mean for a component to render information to the page? What page? And what does “it” refer to - the component, the information or the page?
Next, clarification on the following:
“when the page first loads, render the submit button, buttonOne , to the page.”
What/where is the first page, and how do we know when it loads? What does it mean to “render the submit button to the page?” Which page? Since we are referring to the first page, there must be more than one page…where are the pages…what are the pages…where do we find them?
I think I understand the ternary operator, as I have used it in prior challenges in FCC, but I don’t understand the instructions specific to this exercise. (actually I am finding the instructions and explanations in this React section to be very vague and perfunctory in general).
thanks for considering my questions.
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 = {
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 />
{buttonOne
userAge < 18? buttonThree : buttonTwo
}
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.
Challenge: Use a Ternary Expression for Conditional Rendering
Link to the challenge: