Skip to content

Instantly share code, notes, and snippets.

@interaminense
Created February 27, 2018 02:28
Show Gist options
  • Select an option

  • Save interaminense/2d5a01fa1da7ac60b0d4c43d9fcd7086 to your computer and use it in GitHub Desktop.

Select an option

Save interaminense/2d5a01fa1da7ac60b0d4c43d9fcd7086 to your computer and use it in GitHub Desktop.
Mathematics setNextOperation
setNextOperation() {
let n1 = getRandomNumber(0, this.state.lvl.maxNumber);
let n2 = getRandomNumber(0, this.state.lvl.maxNumber);
let operator = this.getRandomOperator();
let result = CALCULATE(n1, n2, operator);
// If isn't real number, set the next operation
if (isNaN(result) || !isFinite(result)) {
this.setNextOperation();
} else {
if (n1 > n2) {
this.setState({n1, n2});
} else {
this.setState({
n1: n2,
n2: n1
});
}
this.state.operator = operator;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment