sb-game
Version:
50 lines (37 loc) • 3.69 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.calculate = void 0;
var _ = _interopRequireDefault(require(".."));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const gameConditions = 'What is the result of the expression?';
const operators = '+-*';
const calculate = (a, b, operator) => {
switch (operator) {
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
default:
return '';
}
};
exports.calculate = calculate;
const getGameData = () => {
const num1 = (0, _utils.getRandom)(1, 25);
const num2 = (0, _utils.getRandom)(1, 25);
const indexOperation = (0, _utils.getRandom)(0, operators.length - 1);
const operator = operators[indexOperation];
const question = `${num1} ${operator} ${num2}`;
const answer = String(calculate(num1, num2, operator));
return (0, _utils.cons)(question, answer);
};
var _default = () => {
(0, _.default)(gameConditions, getGameData);
};
exports.default = _default;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nYW1lcy9jYWxjLmpzIl0sIm5hbWVzIjpbImdhbWVDb25kaXRpb25zIiwib3BlcmF0b3JzIiwiY2FsY3VsYXRlIiwiYSIsImIiLCJvcGVyYXRvciIsImdldEdhbWVEYXRhIiwibnVtMSIsIm51bTIiLCJpbmRleE9wZXJhdGlvbiIsImxlbmd0aCIsInF1ZXN0aW9uIiwiYW5zd2VyIiwiU3RyaW5nIl0sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBQUE7O0FBQ0E7Ozs7QUFFQSxNQUFNQSxjQUFjLEdBQUcsdUNBQXZCO0FBRUEsTUFBTUMsU0FBUyxHQUFHLEtBQWxCOztBQUVPLE1BQU1DLFNBQVMsR0FBRyxDQUFDQyxDQUFELEVBQUlDLENBQUosRUFBT0MsUUFBUCxLQUFvQjtBQUMzQyxVQUFRQSxRQUFSO0FBQ0UsU0FBSyxHQUFMO0FBQ0UsYUFBT0YsQ0FBQyxHQUFHQyx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