Skip to content

Commit a06bc60

Browse files
committed
6. add game brain-calc and refactoring
1 parent c22444d commit a06bc60

File tree

12 files changed

+98
-48
lines changed

12 files changed

+98
-48
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ brain-games:
55
node bin/brain-games.js
66

77
publish:
8-
bra --dry-run
8+
npm publish --dry-run
99

1010
lint:
1111
npx eslint .
1212

1313
brain-even:
1414
node bin/brain-even.js
1515

16+
brain-calc:
17+
node bin/brain-calc.js
18+
1619
fix:
1720
npx eslint --fix .

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
### Hexlet tests and linter status:
22
[![Actions Status](https://github.com/WisdomQuest/frontend-project-44/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/WisdomQuest/frontend-project-44/actions)
3-
https://asciinema.org/a/zNBty6rqBic6N4Zn5Dmt2Sscb
3+
https://asciinema.org/a/zNBty6rqBic6N4Zn5Dmt2Sscb
4+
https://asciinema.org/a/1gZpYskJ5KBIjVJ1hPz54XRTA

bin/brain-calc.js

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

bin/brain-even.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
2-
import { welcomeUser } from '../src/cli.js';
3-
import evenGame from '../src/cliEven.js';
2+
import { welcomeUser } from '../src/games/cli.js';
3+
import evenGame from '../src/games/cliEven.js';
44

55
welcomeUser();
66
evenGame();

bin/brain-games.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { welcomeUser } from '../src/cli.js';
2+
import { welcomeUser } from '../src/games/cli.js';
33

44
welcomeUser();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"bin": {
2121
"code": "bin/brain-games.js",
2222
"brain-games": "bin/brain-games.js",
23-
"brain-even": "bin/brain-even.js"
23+
"brain-even": "bin/brain-even.js",
24+
"brain-calc": "bin/brain-calc.js"
2425
},
2526
"dependencies": {
2627
"lodash": "^4.17.21",

src/cliEven.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/games/calc.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import roundGame from '../index.js';
2+
import randomNumber from '../utilRandomNumber.js';
3+
4+
const descriptionGame = 'What is the result of the expression?';
5+
6+
const actionGame = () => {
7+
const sign = ['+', '-', '*'];
8+
const randomSiqn = sign[randomNumber(3)];
9+
const Num1 = randomNumber(11);
10+
const Num2 = randomNumber(11);
11+
let correctAnswer = '';
12+
const questionMath = `${Num1} ${randomSiqn} ${Num2}`;
13+
switch (randomSiqn) {
14+
case '+':
15+
correctAnswer = Num1 + Num2;
16+
break;
17+
case '-':
18+
correctAnswer = Num1 - Num2;
19+
break;
20+
case '*':
21+
correctAnswer = Num1 * Num2;
22+
break;
23+
default:
24+
}
25+
return [questionMath, String(correctAnswer)];
26+
};
27+
28+
const calcGame = () => {
29+
console.log(descriptionGame);
30+
roundGame(actionGame);
31+
};
32+
33+
export default calcGame;
File renamed without changes.

src/games/cliEven.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import roundGame from '../index.js';
2+
import randomNumber from '../utilRandomNumber.js';
3+
4+
const descriptionGame = 'Answer "yes" if the number is even, otherwise answer "no".';
5+
6+
const actionGame = () => {
7+
const questNumber = randomNumber();
8+
const isEvenNum = questNumber % 2 === 0;
9+
const correctAnswer = isEvenNum ? 'yes' : 'no';
10+
11+
return [questNumber, correctAnswer];
12+
};
13+
14+
const evenGame = () => {
15+
console.log(descriptionGame);
16+
roundGame(actionGame);
17+
};
18+
19+
export default evenGame;

0 commit comments

Comments
 (0)