Skip to content

Commit

Permalink
update project
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimkulishov committed Sep 11, 2024
1 parent 75de257 commit 29e93ab
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ Your answer: 14
Correct!


## Brain-progression

This is a game where you need to identify the missing number in an arithmetic progression.

### How to play

Run the game with:

```bash
npx brain-progression


== Ссылка на игру

Вы можете найти проект на GitHub: [Brain Games](https://github.com/vadimkulishov/frontend-project-44)
41 changes: 41 additions & 0 deletions bin/brain-progression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

import readlineSync from 'readline-sync';


const generateProgression = (length, step, start) => {
const progression = [];
for (let i = 0; i < length; i++) {
progression.push(start + i * step);
}
return progression;
};

const getRandomIndex = (length) => Math.floor(Math.random() * length);

// Запуск игры
const playProgressionGame = () => {
console.log('What number is missing in the progression?');

const length = 10; // Длина прогрессии
const step = Math.floor(Math.random() * 10) + 1;
const start = Math.floor(Math.random() * 10);

const progression = generateProgression(length, step, start);
const hiddenIndex = getRandomIndex(length);
const hiddenValue = progression[hiddenIndex];

progression[hiddenIndex] = '..';

console.log(`Question: ${progression.join(' ')}`);

const userAnswer = readlineSync.question('Your answer: ');

if (parseInt(userAnswer, 10) === hiddenValue) {
console.log('Correct!');
} else {
console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${hiddenValue}'.`);
console.log('Let\'s try again!');
}
};

export default playProgressionGame;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"brain-games": "bin/brain-games.js",
"brain-even": "bin/brain-even.js",
"brain-calc": "bin/brain-calc.js",
"brain-gcd": "bin/brain-gcd.js"
"brain-gcd": "bin/brain-gcd.js",
"brain-progression": "bin/brain-progression.js"
},
"author": "",
"license": "ISC",
Expand Down

0 comments on commit 29e93ab

Please sign in to comment.