-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
24 lines (21 loc) · 809 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* eslint-disable no-restricted-syntax */
import readlineSync from 'readline-sync';
export const roundsCount = 3;
export const getEngine = (gameRules, gameData) => {
console.log('Welcome to the Brain Games!');
const userName = readlineSync.question('May I have your name? ');
console.log(`Hello, ${userName}!`);
console.log(gameRules);
for (const roundData of gameData) {
const [question, answer] = roundData;
console.log(`Question: ${question}`);
const userAnswer = readlineSync.question('You answer: ');
if (userAnswer !== answer) {
console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${answer}'`);
console.log(`Let's try again, ${userName}!`);
return;
}
console.log('Correct!');
}
console.log(`Congratulations, ${userName}!`);
};