shuffle() {
for(var i = 0; i < 3; i++) {
this.shuffleCard();
}
}
shuffleCard() {
const rand = array[Math.floor(array.length * Math.random())]
if(this.state.computer.length < 2) {
console.log(rand);
this.setState({
computer: [...this.state.computer, rand]
}, () => console.log(this.state.computer));
} else {
this.setState({
player: [...this.state.player, rand]
}, () => console.log(this.state.computer));
}
document.getElementById('shuffleButton').setAttribute('disabled', '');
}
In this code it will only push the lastest generated number and push it to this.state.computer. Why it wouldn’t push the first two numbers? And more importantly what should I do to solve this problem.