Skip to content

Commit 08641c6

Browse files
committed
done 8th step of the project
1 parent 0ad032e commit 08641c6

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111

1212
## Brain GCD
1313
[![asciicast](https://asciinema.org/a/nP0uI7dz54y5BVvA2rY9Fk58g.svg)](https://asciinema.org/a/nP0uI7dz54y5BVvA2rY9Fk58g)
14+
15+
## Brain Progression
16+
[![asciicast](https://asciinema.org/a/FwJq0UlMtfHyl7DVNShYaGBFR.svg)](https://asciinema.org/a/FwJq0UlMtfHyl7DVNShYaGBFR)
17+

bin/brain-progression.js

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

demo.cast5

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{"version": 2, "width": 80, "height": 24, "timestamp": 1758535058, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.223326, "o", "\u001b[?2004h\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ "]
3+
[2.171645, "o", "\u001b[7mbrain-p\u001b[27m\u001b[7mr\u001b[27m\u001b[7mogression\u001b[27m"]
4+
[2.925325, "o", "\u001b[A\r\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ brain-progression\r\n"]
5+
[2.925482, "o", "\u001b[?2004l\r"]
6+
[2.971889, "o", "Welcome to the Brain Games!\r\n"]
7+
[2.971993, "o", "What number is missing in the progression?\r\n"]
8+
[2.97278, "o", "May I have your name? "]
9+
[4.887767, "o", "M"]
10+
[5.157917, "o", "i"]
11+
[5.37143, "o", "c"]
12+
[5.633196, "o", "h"]
13+
[5.742113, "o", "a"]
14+
[5.968377, "o", "e"]
15+
[6.191171, "o", "l"]
16+
[6.823202, "o", "\r\n"]
17+
[6.824584, "o", "Hello, Michael!\r\n"]
18+
[6.82467, "o", "Question: 2 .. 6 8 10 12 14 16 18 20\r\n"]
19+
[6.824896, "o", "Your answer: "]
20+
[9.52151, "o", "4"]
21+
[10.642465, "o", "\r\n"]
22+
[10.643201, "o", "Correct!\r\nQuestion: .. 21 25 29 33 37 41 45 49 53\r\n"]
23+
[10.643303, "o", "Your answer: "]
24+
[19.235123, "o", "1"]
25+
[19.371739, "o", "8"]
26+
[20.163127, "o", "\r\n"]
27+
[20.163484, "o", "'18' is wrong answer ;(. Correct answer was '17'.\r\n"]
28+
[20.163555, "o", "Let's try again, Michael!\r\n"]
29+
[20.171226, "o", "\u001b[?2004h\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ "]
30+
[25.384141, "o", "\u001b[7mbrain-p\u001b[27m\u001b[7mr\u001b[27m\u001b[7mogression\u001b[27m"]
31+
[27.251469, "o", "\u001b[A\r\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ brain-progression\r\n\u001b[?2004l\r"]
32+
[27.286314, "o", "Welcome to the Brain Games!\r\nWhat number is missing in the progression?\r\n"]
33+
[27.287316, "o", "May I have your name? "]
34+
[29.241781, "o", "S"]
35+
[29.577165, "o", "a"]
36+
[29.762741, "o", "m"]
37+
[30.580905, "o", "\r\n"]
38+
[30.581754, "o", "Hello, Sam!\r\n"]
39+
[30.581826, "o", "Question: 14 .. 20 23 26 29 32 35 38 41\r\n"]
40+
[30.582079, "o", "Your answer: "]
41+
[35.260902, "o", "1"]
42+
[35.672464, "o", "7"]
43+
[37.222301, "o", "\r\n"]
44+
[37.223142, "o", "Correct!\r\nQuestion: 14 18 22 26 30 34 38 .. 46 50\r\n"]
45+
[37.223362, "o", "Your answer: "]
46+
[42.656471, "o", "4"]
47+
[42.729159, "o", "2"]
48+
[44.865058, "o", "\r\n"]
49+
[44.865478, "o", "Correct!\r\n"]
50+
[44.865716, "o", "Question: .. 16 18 20 22 24 26 28 30 32\r\nYour answer: "]
51+
[50.317323, "o", "1"]
52+
[50.421276, "o", "4"]
53+
[51.396913, "o", "\r\n"]
54+
[51.397303, "o", "Correct!\r\n"]
55+
[51.397477, "o", "Congratulations, Sam!\r\n"]
56+
[51.404156, "o", "\u001b[?2004h\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ "]
57+
[57.294476, "o", "\u001b[?2004l\r\r\nexit\r\n"]

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"brain-games": "bin/brain-games.js",
2222
"brain-even": "bin/brain-even.js",
2323
"brain-calc": "bin/brain-calc.js",
24-
"brain-gcd": "bin/brain-gcd.js"
24+
"brain-gcd": "bin/brain-gcd.js",
25+
"brain-progression": "bin/brain-progression.js"
2526
},
2627
"dependencies": {
2728
"readline-sync": "^1.4.10"

src/games/progression.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import runEngine from '../index.js'
2+
import getRandomNumber from '../utils.js'
3+
4+
const rule = 'What number is missing in the progression?'
5+
6+
const getProgression = (start, step, length = 10) => {
7+
const progression = []
8+
for (let i = 0; i < length; i += 1) {
9+
progression.push(start + i * step)
10+
}
11+
return progression
12+
}
13+
14+
const makeRound = () => {
15+
const start = getRandomNumber(1, 20)
16+
const step = getRandomNumber(1, 5)
17+
const length = 10
18+
const progression = getProgression(start, step, length)
19+
20+
const hiddenIndex = getRandomNumber(0, length - 1)
21+
const correctAnswer = String(progression[hiddenIndex])
22+
23+
progression[hiddenIndex] = '..'
24+
25+
const question = progression.join(' ')
26+
return [question, correctAnswer]
27+
}
28+
29+
const runProgressionGame = () => runEngine(rule, makeRound)
30+
31+
export default runProgressionGame

0 commit comments

Comments
 (0)