Created
February 28, 2018 04:37
-
-
Save interaminense/76d8c2018af3ace82a954d62441ab741 to your computer and use it in GitHub Desktop.
Mathematics Utils
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
/** | |
* Object list language | |
*/ | |
const LANGUAGE = { | |
errors: 'errors', | |
hits: 'hits', | |
next: 'next', | |
ops: '๐คฆ Ops, try again!', | |
totalErrors: 'total erros', | |
totalHits: 'total hits', | |
yeah: '๐ Yeah, congratulations!', | |
initGame: '๐ฎ Mathematics', | |
startGame: '๐ Start game', | |
finishGame: '๐ฏ Game Over', | |
reset: 'reset', | |
startGameAgain: '๐ Start game again', | |
time: '๐' | |
}; | |
/** | |
* Return result calculate | |
* @param {number} n1 | |
* @param {number} n2 | |
* @param {string} operator | |
*/ | |
const CALCULATE = (n1, n2, operator) => { | |
let result = 0; | |
switch(operator) { | |
case '+': result = n1 + n2; break; | |
case '-': result = n1 - n2; break; | |
case 'x': result = n1 * n2; break; | |
case 'รท': result = n1 / n2; break; | |
default: result = null; break; | |
} | |
return result.toFixed(0); | |
}; | |
/** | |
* Return the calculate timeout amout | |
* @param {number} time | |
*/ | |
const getCalcTimeoutAmout = (time) => { | |
return 100 / time; | |
} | |
/** | |
* Return random number | |
* @param {number} min | |
* @param {number} max | |
*/ | |
const getRandomNumber = (min, max) => { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
export {LANGUAGE, CALCULATE, getCalcTimeoutAmout, getRandomNumber}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment