Here is what I have:
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() {
let expression = Math.random > .5;
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>
);
}
};
Everything passes except the last requirement: 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!
.
When you click the “Play Again” button, it seems like there is not a new random number generated.
Is the component not rendered again (and so generating a different random number) whenever the button is clicked?