I'm making a rock paper scissors game and as I am coding, I am testing out certain parts and the random number generator works by itself and so do the other parts but they don't work altogether.
I don't know what to try but I've tried different ways to do the number generator.
constructor() {
super();
this.state = {
rockPaperScissorsComputer: ['rock','paper','scissors'],
random: null
};
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
const min = 1;
const max = 100;
const random = min + (Math.random() * (max - min));
this.setState({ random })
}
render() {
return (
<div>
<button value="Click me!" onClick={this.handleClick}>Click me</button>
<h1> {this.state.rockPaperScissorsComputer[this.state.random]} </h1>
</div>
);
}
It should display rock paper or scissors every time I click the button but it just does nothing.
Aucun commentaire:
Enregistrer un commentaire