Skip to content

Instantly share code, notes, and snippets.

@interaminense
Created February 28, 2018 04:37
Show Gist options
  • Save interaminense/76d8c2018af3ace82a954d62441ab741 to your computer and use it in GitHub Desktop.
Save interaminense/76d8c2018af3ace82a954d62441ab741 to your computer and use it in GitHub Desktop.
Mathematics Utils
/**
* 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