Nistler/project-lvl1-s132

View on GitHub
src/games/calculator.js

Summary

Maintainability
A
0 mins
Test Coverage
import { cons } from 'hexlet-pairs';
import RandomNumber from '../utils';
import startGame from '..';

const gameDescription = 'What is the result of the expression?';
const maxNum = 100;

const makeTask = () => {
  const leftNum = RandomNumber(maxNum);
  const rightNum = RandomNumber(maxNum);
  switch (RandomNumber(3)) {
    case 1:
      return cons(`${leftNum} + ${rightNum}`, `${leftNum + rightNum}`);
    case 2:
      return cons(`${leftNum} - ${rightNum}`, `${leftNum - rightNum}`);
    default:
      return cons(`${leftNum} * ${rightNum}`, `${leftNum * rightNum}`);
  }
};

export default () => startGame(makeTask, gameDescription);