Skip to content

Commit 9fe4ee8

Browse files
rootroot
authored andcommitted
fix index.js
1 parent 907e89e commit 9fe4ee8

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

index.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import readlineSync from "readline-sync"
22
export const needAnswers = 3;
33
const TheMotor = (feat, alert) =>{
4-
console.log('Welcome to the Brain Games!');
5-
const name = readlineSync.question('May I have your name? ');
6-
console.log(`Hello, ${name}!`);
7-
console.log(alert);
8-
for (let i = 1; i <=needAnswers; i+=1){
9-
const [exp, rightAnswer] = feat();
10-
console.log(`Question: ${exp} `);
11-
const userAnswer = readlineSync.question('Your Answer: ');
12-
if (userAnswer !== rightAnswer) {
13-
console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${rightAnswer}'. \nLet's try again, ${name}!`);
14-
return;
15-
}
16-
console.log('Correct!');
17-
if (i === needAnswers) {
18-
console.log(`Congratulations, ${name}!`);
19-
return;
20-
}
4+
const maxRoundCount = 3;
5+
6+
console.log('Welcome to the Brain Games!');
7+
const userName = readlineSync.question('May I have your name? ');
8+
console.log(`Hello, ${userName}!`);
9+
10+
console.log(alert);
11+
12+
for (let i = 1; i <= maxRoundCount; i += 1) {
13+
const roundData = feat();
14+
const [question, correctAnswer] = roundData;
15+
console.log(`Question: ${question}`);
16+
const userAnswer = readlineSync.question('Your answer: ');
17+
18+
if (userAnswer !== correctAnswer) {
19+
console.log(`"${userAnswer}" is wrong answer ;(. Correct answer was "${correctAnswer}"`);
20+
console.log(`Let's try again, ${userName}!`);
21+
22+
return;
2123
}
22-
}
24+
25+
console.log('Correct!');
26+
}
27+
console.log(`Congratulations, ${userName}!`);
28+
};
29+
2330
export {TheMotor};

0 commit comments

Comments
 (0)