Skip to content

Commit ac3b148

Browse files
rootroot
authored andcommitted
f work on brain-even
1 parent f612929 commit ac3b148

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "[![Actions Status](https://github.com/aptart/frontend-project-44/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/aptart/frontend-project-44/actions)",
66
"main": "index.js",
77
"bin": {
8-
"brain-games": "bin/brain-games.js"
8+
"brain-games": "bin/brain-games.js",
99
"brain-even": "bin/brain-even.js"
1010
},
1111
"scripts": {

src/brainEven.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
import readlineSync from 'readline-sync';
22
const getRandomNum = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
33
const needAnswers = 3
4-
const TheMotor = (feature, description) => {
4+
function TheMotor(feature, description) {
55
console.log('Welcome to the Brain Games!');
66
const name = readlineSync.question('May I have your name? ');
77
console.log(`Hello, ${name}!`);
88
console.log(description);
9-
for (let i = 1; i <= correctAnswers; i += 1) {
10-
const [exp, rightAnswer] = feature();
11-
console.log(`Question: ${exp} `);
12-
const userAnswer = readlineSync.question('Your Answer: ');
13-
if (userAnswer !== rightAnswer) {
14-
console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${rightAnswer}'. \nLet's try again, ${name}!`);
15-
return;
16-
}
17-
console.log('Correct!');
18-
if (i === needAnswers) {
19-
console.log(`Congratulations, ${name}!`);
20-
return;
21-
}
9+
for (let i = 1; i <=needAnswers, i+=1){
10+
const [exp, rightAnswer] = feature();
11+
console.log(`Question: ${exp} `);
12+
const userAnswer = readlineSync.question('Your Answer: ');
13+
if (userAnswer !== rightAnswer) {
14+
console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${rightAnswer}'. \nLet's try again, ${name}!`);
15+
return;
16+
}
17+
console.log('Correct!');
18+
if (i === needAnswers) {
19+
console.log(`Congratulations, ${name}!`);
20+
return;
21+
}
2222
}
23-
};
23+
}
2424
const alert = '"yes" if the number is even, otherwise answer "no".';
2525
const Game = ()=>{
2626
const minNum = 1;
2727
const maxNum = 1000;
2828
const randomNum = getRandomNum(minNum, maxNum);
2929
const rightAnswer = randomNum % 2 === 0 ? 'yes' : 'no';
30-
const coll = [randomNum, rightAnswer];
31-
return coll;
30+
return [randomNum, rightAnswer];
3231

3332
}
3433
const gameven = () =>{

0 commit comments

Comments
 (0)