function Square(props) { var button = props.clicked; var btnStyle = {background: 'silver'} if(button){ btnStyle = {background: props.value} } return ( ); } class Board extends React.Component { constructor(props) { super(props); this.state = { redjar: ['red','red', 'red', 'red', 'red','red', 'red','blue', 'blue', 'blue'], bluejar: ['blue', 'blue', 'blue', 'blue', 'blue', 'blue', 'blue', 'red', 'red', 'red'], btnStyle: false, btnColors: Array(10).fill('silver'), signal: 'silver' } } renderSquare(i, color) { return ( this.handleClick(i, color)}/>); } handleClick(i, color){ this.setState({btnStyle: true}); const rainbow = this.state.btnColors.slice(); rainbow[i] = color; this.setState({btnColors: rainbow}); this.setState({signal: color}); document.getElementById('signal').value = color; } render() { const colors = this.props.marbles return (
{this.renderSquare(0, colors[0])} {this.renderSquare(1, colors[1])} {this.renderSquare(2, colors[2])} {this.renderSquare(3, colors[3])} {this.renderSquare(4, colors[4])} {this.renderSquare(5, colors[5])} {this.renderSquare(6, colors[6])} {this.renderSquare(7, colors[7])} {this.renderSquare(8, colors[8])} {this.renderSquare(9, colors[9])}
); } } class Game extends React.Component { constructor(props) { super(props); this.state = { redjar: ['red','red', 'red', 'red', 'red','red', 'red','blue', 'blue', 'blue'], bluejar: ['blue', 'blue', 'blue', 'blue', 'blue', 'blue', 'blue', 'red', 'red', 'red'] } } render() { const rand1 = this.props.jar var jar = []; if(rand1 == 'True'){ jar = this.state.bluejar } if(rand1 == 'False'){ jar = this.state.redjar } var colors = []; var i = 0; while(i < 10){ const rand2 = Math.floor(Math.random()*(jar.length-1)); var color = jar[rand2] colors[i] = color jar.splice(rand2, 1); if(rand1 == 'True'){ this.state.bluejar = jar } if(rand1 == 'False'){ this.state.redjar = jar } i = i+1; } return (
{/* status */}
    {/* TODO */}
); } } // ======================================== const domContainer = document.querySelector('#root'); ReactDOM.render(, domContainer);