|
1 | | -import readlineSync from 'readline-sync'; |
| 1 | +import readlineSync from 'readline-sync' |
2 | 2 |
|
3 | | -const roundCount = 3; |
| 3 | +const roundCount = 3 |
4 | 4 |
|
5 | 5 | const runEngine = (rule, getQuestionAndAnswer) => { |
6 | | - console.log('Welcome to the Brain Games!'); |
7 | | - console.log(rule); |
| 6 | + console.log('Welcome to the Brain Games!') |
| 7 | + console.log(rule) |
8 | 8 |
|
9 | | - const name = readlineSync.question('May I have your name? '); |
10 | | - console.log(`Hello, ${name}!`); |
| 9 | + const name = readlineSync.question('May I have your name? ') |
| 10 | + console.log(`Hello, ${name}!`) |
11 | 11 |
|
12 | 12 | for (let i = 0; i < roundCount; i += 1) { |
13 | | - const [question, correctAnswer] = getQuestionAndAnswer(); |
14 | | - console.log(`Question: ${question}`); |
15 | | - const userAnswer = readlineSync.question('Your answer: '); |
| 13 | + const [question, correctAnswer] = getQuestionAndAnswer() |
| 14 | + console.log(`Question: ${question}`) |
| 15 | + const userAnswer = readlineSync.question('Your answer: ') |
16 | 16 |
|
17 | 17 | if (userAnswer !== correctAnswer) { |
18 | | - console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${correctAnswer}'.`); |
19 | | - console.log (`Let's try again, ${name}!`); |
20 | | - return; |
| 18 | + console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${correctAnswer}'.`) |
| 19 | + console.log (`Let's try again, ${name}!`) |
| 20 | + return |
21 | 21 | } |
22 | 22 |
|
23 | | - console.log('Correct!'); |
| 23 | + console.log('Correct!') |
24 | 24 | } |
25 | 25 |
|
26 | | - console.log(`Congratulations, ${name}!`); |
27 | | -}; |
| 26 | + console.log(`Congratulations, ${name}!`) |
| 27 | +} |
28 | 28 |
|
29 | | -export default runEngine; |
| 29 | +export default runEngine |
0 commit comments