Hi Guys,
I’ve been having an issue with this challenge, I’ve followed the hints and then entered on the suggested solution inside, but it was giving me errors.
I copy-pasted everything from solution bit by bit but still the same.
Does anyone know where the error is?
From the error messages, this only is giving me trouble:
X
When the GameOfChance
component is first mounted to the DOM and each time the button is clicked thereafter, a single h1
element should be returned that randomly renders either You Win!
or You Lose!
.
class Results extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<h1>
{ this.props.fiftyFifty ? "You Win!" : "You Lose!" }
</h1>
)
};
};
class GameOfChance extends React.Component {
constructor(props) {
super(props);
this.state = {
counter: 1
}
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState({
counter: this.state.counter + 1 // change code here
});
}
render() {
const expression = Math.random() >= 0.5 ? true : false; // change code here
return (
<div>
<button onClick={this.handleClick}>Play Again</button>
{ /* change code below this line */ }
<Results fiftyFifty={expression} />
{ /* change code above this line */ }
<p>{'Turn: ' + this.state.counter}</p>
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15
.
Challenge: Render Conditionally from Props
Link to the challenge: