我正在做石头,纸,剪刀游戏和数学运算。由于它在我的条件渲染语句中说它是一个功能,所以地板不起作用。
我尝试消除math.floow,只将其放在随机数起源的地方,但这并不起作用,因为它说的是同一件事。
constructor() {
super();
this.state = {
rockPaperScissorsComputer: ['rock', 'paper', 'scissors'],
rockPaperScissorsUser: null,
random: null
};
this.handleClickRock = this.handleClickRock.bind(this);
this.handleClickPaper = this.handleClickPaper.bind(this);
this.handleClickScissors = this.handleClickScissors.bind(this);
}
handleClickRock() {
const min = 0;
const max = 3;
const random = min + (Math.random() * (max - min));
this.setState({ random })
this.setState({
rockPaperScissorsUser: 'rock'
})
}
handleClickPaper() {
const min = 0;
const max = 3;
const random = min + (Math.random() * (max - min));
this.setState({ random })
this.setState({
rockPaperScissorsUser: 'paper'
})
}
handleClickScissors() {
const min = 0;
const max = 3;
const random = min + (Math.random() * (max - min));
this.setState({ random })
this.setState({
rockPaperScissorsUser: 'scissors'
})
}
render() {
return (
<div>
<button value="Click me!" onClick={this.handleClickRock}>Rock</button>
<button value="Click me!" onClick={this.handleClickPaper}>Paper</button>
<button value="Click me!" onClick={this.handleClickScissors}>Scissors</button>
<h1> {this.state.rockPaperScissorsComputer[Math.floor(this.state.random)]} </h1>
{
this.state.rockPaperScissorsComputer[Math.floor(this.state.random)] ==
this.state.rockPaperScissorsUser ? <h1> It was a tie </h1> :
this.state.rockPaperScissorsUser ==
'rock' && Math.Floor(this.state.random) == 2
|| this.state.rockPaperScissorsUser == 'paper' &&
Math.Floor(this.state.random) == 0 ||
this.state.rockPaperScissorsUser =='scissors' &&
Math.Floor(this.state.random) == 1
? <h1>You win</h1> : <h1>You lost!</h1>
}
</div>
);
}
我希望代码能够输出功能齐全的剪刀石头布游戏,但是,当我单击按钮时,它给我一个错误:“ Math.Floor is not function”。
答案 0 :(得分:0)
使用Math.floor,floor必须小写。
答案 1 :(得分:0)