Skip to content

Commit 43705a6

Browse files
committed
Add new progression game
1 parent cd398da commit 43705a6

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

bin/brain-progression.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import run from '../src/games/progression.js';
4+
5+
run();

src/games/progression.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import playGame from '../index.js';
2+
3+
const rules = 'What number is missing in the progression?';
4+
5+
const findNumberInProgression = () => {
6+
const increasedBy = Math.floor(Math.random() * 10) + 1;
7+
let progressionNumber = Math.floor(Math.random() * 50);
8+
const progression = [progressionNumber];
9+
10+
for (let i = 1; i < 10; i += 1) {
11+
progressionNumber += increasedBy;
12+
progression.push(progressionNumber);
13+
}
14+
15+
const position = Math.floor(Math.random() * 10);
16+
const correctAnswer = progression[position];
17+
progression[position] = '..';
18+
19+
return [progression.join(' '), String(correctAnswer)];
20+
};
21+
22+
export default () => playGame(rules, findNumberInProgression);

0 commit comments

Comments
 (0)