Skip to content

Commit de8d032

Browse files
committed
Added game brain-gcd
1 parent bdcc131 commit de8d032

File tree

4 files changed

+114
-2
lines changed

4 files changed

+114
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
## Демонстрация работы brain-even.js
55
[Смотреть запись в терминале]( https://asciinema.org/connect/a69561bc-070b-40e4-9a31-cfc173f7f842)
66
## Демонстрация работы brain-calc.js
7-
[Смотреть запись в терминале]( https://asciinema.org/a/5OadaYOMLkEyfb4kMb1yoFihC)
7+
[Смотреть запись в терминале]( https://asciinema.org/a/5OadaYOMLkEyfb4kMb1yoFihC)
8+
## Демонстрация работы brain-gcd.js
9+
[Смотреть запись в терминале](https://asciinema.org/a/QZBrkNqHteOK85ZmxKz65xaXY)

bin/brain-gcd.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import playGame from '../src/index.js';
2+
3+
const calculateGCD = (a, b) => {
4+
while (b !== 0) {
5+
const temp = b;
6+
b = a % b;
7+
a = temp;
8+
}
9+
return a;
10+
};
11+
12+
const getQuestionAndAnswer = () => {
13+
const num1 = Math.floor(Math.random() * 100) + 1;
14+
const num2 = Math.floor(Math.random() * 100) + 1;
15+
const question = `${num1} ${num2}`;
16+
const correctAnswer = String(calculateGCD(num1, num2));
17+
return { question, correctAnswer };
18+
};
19+
20+
const playGameGCD = () => {
21+
const gameQuestion = 'Find the greatest common divisor of given numbers.';
22+
playGame(getQuestionAndAnswer, gameQuestion);
23+
};
24+
25+
playGameGCD();

bin/demo2.cast

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{"version": 2, "width": 120, "height": 30, "timestamp": 1740844147, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.019892, "o", "\u001b[?2004h\u001b]0;katerina_che@LAPTOP-V6LNI5O7: ~/frontend-project-44/bin\u0007\u001b[01;32mkaterina_che@LAPTOP-V6LNI5O7\u001b[00m:\u001b[01;34m~/frontend-project-44/bin\u001b[00m$ "]
3+
[2.263375, "o", "n"]
4+
[2.776481, "o", "o"]
5+
[3.178072, "o", "d"]
6+
[3.503836, "o", "e"]
7+
[3.798709, "o", " "]
8+
[4.115127, "o", "b"]
9+
[4.996483, "o", "r"]
10+
[5.582263, "o", "a"]
11+
[5.927034, "o", "i"]
12+
[6.275444, "o", "n"]
13+
[6.917154, "o", "-"]
14+
[10.601548, "o", "g"]
15+
[11.354675, "o", "c"]
16+
[11.586777, "o", "d"]
17+
[13.049839, "o", "."]
18+
[13.911225, "o", "j"]
19+
[14.365442, "o", "s"]
20+
[15.059133, "o", "\r\n\u001b[?2004l\r"]
21+
[15.122977, "o", "Welcome to the Brain Games!\r\n"]
22+
[15.125544, "o", "May I have your name?"]
23+
[16.67687, "o", "K"]
24+
[17.177819, "o", "a"]
25+
[17.307754, "o", "t"]
26+
[17.675667, "o", "e"]
27+
[18.521698, "o", "\r\n"]
28+
[18.522485, "o", "Hello, Kate!\r\nFind the greatest common divisor of given numbers.\r\n"]
29+
[18.522874, "o", "Question: 73 8\r\n"]
30+
[18.523026, "o", "Your answer: "]
31+
[21.212378, "o", "1"]
32+
[21.722245, "o", "\r\n"]
33+
[21.722816, "o", "Correct!\r\n"]
34+
[21.723071, "o", "Question: 42 67\r\n"]
35+
[21.72327, "o", "Your answer: "]
36+
[24.43157, "o", "1"]
37+
[24.787712, "o", "\r\n"]
38+
[24.787992, "o", "Correct!\r\n"]
39+
[24.788143, "o", "Question: 87 38\r\n"]
40+
[24.788416, "o", "Your answer: "]
41+
[29.102306, "o", "1"]
42+
[29.866143, "o", "\r\n"]
43+
[29.866623, "o", "Correct!\r\n"]
44+
[29.867301, "o", "Congratulations, Kate!\r\n"]
45+
[29.873479, "o", "\u001b[?2004h\u001b]0;katerina_che@LAPTOP-V6LNI5O7: ~/frontend-project-44/bin\u0007\u001b[01;32mkaterina_che@LAPTOP-V6LNI5O7\u001b[00m:\u001b[01;34m~/frontend-project-44/bin\u001b[00m$ "]
46+
[31.858464, "o", "n"]
47+
[33.087656, "o", "o"]
48+
[33.282901, "o", "d"]
49+
[33.553931, "o", "e"]
50+
[34.05128, "o", " "]
51+
[34.408958, "o", "b"]
52+
[34.975478, "o", "r"]
53+
[35.179269, "o", "a"]
54+
[35.648259, "o", "i"]
55+
[35.958225, "o", "n"]
56+
[36.396, "o", "-"]
57+
[37.345917, "o", "g"]
58+
[37.969912, "o", "c"]
59+
[38.149923, "o", "d"]
60+
[39.132986, "o", "."]
61+
[40.024529, "o", "j"]
62+
[40.454954, "o", "s"]
63+
[43.301926, "o", "\r\n\u001b[?2004l\r"]
64+
[43.355848, "o", "Welcome to the Brain Games!\r\n"]
65+
[43.358089, "o", "May I have your name?"]
66+
[44.779191, "o", "K"]
67+
[45.295548, "o", "a"]
68+
[45.483327, "o", "t"]
69+
[45.71863, "o", "e"]
70+
[46.8147, "o", "\r\n"]
71+
[46.815579, "o", "Hello, Kate!\r\nFind the greatest common divisor of given numbers.\r\n"]
72+
[46.815908, "o", "Question: 96 5\r\n"]
73+
[46.816128, "o", "Your answer: "]
74+
[51.284326, "o", "1"]
75+
[51.633777, "o", "\r\n"]
76+
[51.634384, "o", "Correct!\r\n"]
77+
[51.634547, "o", "Question: 43 16\r\n"]
78+
[51.635097, "o", "Your answer: "]
79+
[54.831839, "o", "3"]
80+
[55.118029, "o", "\r\n"]
81+
[55.118329, "o", "3 is wrong answer ;(. Correct answer was 1.\r\n"]
82+
[55.118561, "o", "Let's try again, Kate!\r\n"]
83+
[55.125033, "o", "\u001b[?2004h\u001b]0;katerina_che@LAPTOP-V6LNI5O7: ~/frontend-project-44/bin\u0007\u001b[01;32mkaterina_che@LAPTOP-V6LNI5O7\u001b[00m:\u001b[01;34m~/frontend-project-44/bin\u001b[00m$ "]
84+
[57.802309, "o", "\u001b[?2004l\r\r\nexit\r\n"]

package.json

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

0 commit comments

Comments
 (0)