macanel/project-lvl1-s412

View on GitHub
src/games/calc.js

Summary

Maintainability
A
0 mins
Test Coverage
import { cons } from 'hexlet-pairs';
import { getRandomNumber, gameTemplate } from '..';

const taskDescription = 'What is the result of the expression?';

const calc = () => {
  const randomNumber1 = getRandomNumber(0, 50);
  const randomNumber2 = getRandomNumber(0, 50);
  const signSym = getRandomNumber(1, 3);
  let correctAnswer = 0;
  let question = '';
  if (signSym === 1) {
    correctAnswer = randomNumber1 + randomNumber2;
    question = `${randomNumber1} + ${randomNumber2}`;
  } else if (signSym === 2) {
    correctAnswer = randomNumber1 - randomNumber2;
    question = `${randomNumber1} - ${randomNumber2}`;
  } else {
    correctAnswer = randomNumber1 * randomNumber2;
    question = `${randomNumber1} * ${randomNumber2}`;
  }

  return cons(question, correctAnswer);
};
export default () => gameTemplate(calc, taskDescription);