AAbenites/project-lvl1-s450

View on GitHub
src/games/even.js

Summary

Maintainability
A
0 mins
Test Coverage
import { random } from 'lodash';
import { cons } from 'hexlet-pairs';
import loop from '..';

const gameDescription = 'Answer "yes" if number even otherwise answer "no".';

const isEven = num => num % 2 === 0;

const getCorrectAnswer = num => (isEven(num) ? 'yes' : 'no');

const askQuestion = () => {
  const question = random(1, 100);
  const correctAnswer = getCorrectAnswer(question);
  return cons(question, correctAnswer);
};

export default () => loop(gameDescription, askQuestion);