Skip to content

Commit

Permalink
fix progression.js index.js gcd.js calc.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana-js committed Oct 24, 2023
1 parent 90fde84 commit b1097cc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/games/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const playCalc = () => {
const operators = ['+', '-', '*'];
const operator = operators[getRandomANumber(0, 3)];
const question = `${numberOne} ${operator} ${numberTwo}`;
const answerCorrect = rightAnswer(numberOne, numberTwo, operator);
const answerCorrect = String(rightAnswer(numberOne, numberTwo, operator));
return [question, answerCorrect];
};
const runCalcGame = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/games/gcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const playMaxGeneralDivider = () => {
const numberOne = getRandomANumber(0, 100);
const numberTwo = getRandomANumber(0, 100);
const question = `${numberOne} ${numberTwo}`;
const answerCorrect = getMaxDevidor(numberOne, numberTwo);
const answerCorrect = String(getMaxDevidor(numberOne, numberTwo));
return [question, answerCorrect];
};
const runGcdGame = () => {
Expand Down
28 changes: 14 additions & 14 deletions src/games/progression.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import game from '../index.js';

import getRandomANumber from '../utils.js';

const getArray = () => {
const a = 5;
const b = 10;
const lengthArray = getRandomANumber(a, b);
const getArray = (step, firstEl, countEl) => {
const array = [];
const startNum = getRandomANumber(0, 100);
const step = Math.ceil(Math.random() * 10);
for (let i = 0; i < lengthArray; i += 1) {
const current = startNum + step * i;
for (let i = 0; i < countEl; i += 1) {
const current = firstEl + step * i;
array.push(current);
}
const indexMissing = getRandomANumber(0, lengthArray);
const missingElement = array[indexMissing];
array.splice(indexMissing, 1, '..');
return [array, missingElement];
return array;
};

const progression = () => {
const [expression, answerCorrect] = getArray();
const question = expression.join(' ');
const step = Math.ceil(Math.random() * 10);
const countEl = getRandomANumber(5, 10);
const firstEl = getRandomANumber(0, 100);
const array = getArray(step, firstEl, countEl);

const indexMissing = getRandomANumber(0, countEl);
const missingElement = array[indexMissing];
array.splice(indexMissing, 1, '..');
const answerCorrect = String(missingElement);
const question = array.join(' ');
return [question, answerCorrect];
};
const runProgressionGame = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const game = (playGame, condition) => {
const [question, answerCorrect] = playGame();
console.log(`Question: ${question}`);
const answerUser = readlineSync.question('Your answer: ');
if (answerUser === String(answerCorrect)) {
if (answerUser === answerCorrect) {
console.log('Correct!');
} else {
console.log(`'${answerUser}' is wrong answer ;(. Correct answer was '${answerCorrect}'.\nLet's try again, ${userName}!`);
Expand Down

0 comments on commit b1097cc

Please sign in to comment.