Created
February 27, 2018 02:28
-
-
Save interaminense/2d5a01fa1da7ac60b0d4c43d9fcd7086 to your computer and use it in GitHub Desktop.
Mathematics setNextOperation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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