cududoma/project-lvl1-s232

View on GitHub
src/games/game-progression.js

Summary

Maintainability
A
0 mins
Test Coverage
import { commonGameLogic, getRandomInt } from '../index';


const progressionGameCondition = () => {
  const step = getRandomInt(2, 5);
  const startNum = getRandomInt(2, 9);
  const sequenceLenght = 10;
  const skipped = getRandomInt(2, sequenceLenght - 2);
  const progession = [];
  for (let i = 0; i < sequenceLenght; i += 1) {
    progession.push(startNum + (step * i));
  }

  const answer = progession[skipped];
  progession[skipped] = '..';
  const question = progession.join(' ');
  return [question, answer];
};

const progressionGame = () => {
  commonGameLogic('What number is missing in this progression?', progressionGameCondition);
};

export default progressionGame;