I made a simple rock-paper-scissors game. During onclick
I call a function to add a number and change the state. Within that function I then call 2 more functions, one picks a random number between 1 and 3 and converts it to rock/paper/scissors and assigns it to the state, then a another function figures out who won:
addToInput = val =>{
this.setState({
input:val
});
this.picknum();
this.pickwin();
}
https://codepen.io/russiandobby/pen/xeRYzw?editors=0002
At first I thought that picknum
and pickwin
would get executed at the same time, however even if I try to call pickwin
within picknum
it still won't work.
What seems to happen is that when pickwin
executes it looks at an old state instead of the state that gets changed by picknum
.
How can I fix this problem?