Skip to content

Commit 41341f6

Browse files
rootroot
authored andcommitted
Add new game brain-progression
1 parent 3132877 commit 41341f6

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ brain-calc:
88
node bin/brain-calc.js
99
brain-gcd:
1010
node bin/brain-gcd.js
11+
brain-progression:
12+
node bin/brain-progression.js
1113
publish:
1214
npm publish --dry-run
1315
lint:

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 gamePRG from "../src/brainPGRESS.js";
4+
5+
gamePRG();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"brain-games": "bin/brain-games.js",
99
"brain-even": "bin/brain-even.js",
1010
"brain-calc": "bin/brain-calc.js",
11-
"brain-gcd": "bin/brain-gcd.js"
11+
"brain-gcd": "bin/brain-gcd.js",
12+
"brain-progression": "bin/brain-progression.js"
1213
},
1314
"scripts": {
1415
"test": "echo \"Error: no test specified\" && exit 1"

src/brainPGRESS.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getRandomNum } from "./brainEven.js";
2+
import { TheMotor } from "../index.js";
3+
const genPRG = (length, firstElem, prgStep)=>{
4+
const progression = [];
5+
for (let i = 0; i < length; i += 1) {
6+
progression.push(firstElem + prgStep * i);
7+
}
8+
return progression;
9+
}
10+
const alert = "What number is missing in the progression?";
11+
const genRounds = () =>{
12+
const progressionLength = 10;
13+
const firstElem = getRandomNum(1, 10);
14+
const prgStep = getRandomNum(2,10);
15+
const progression = genPRG(progressionLength, firstElem, prgStep);
16+
const indexOfHide = getRandomNum(0, progressionLength - 1);
17+
const hiddenElem = progression[indexOfHide];
18+
progression[indexOfHide] = "..";
19+
const question = progression.join(" ");
20+
const rightAnswer = hiddenElem.toString();
21+
return [question, rightAnswer];
22+
23+
}
24+
const gamePRG = () =>{
25+
TheMotor(alert, genRounds);
26+
}
27+
export default gamePRG;

0 commit comments

Comments
 (0)