src/index.js
import { car, cdr } from '@hexlet/pairs';
import readlineSync from 'readline-sync';
const attemptsNum = 3;
export default (genGameData, gameDescription) => {
console.log('Welcome to the Brain Games!');
const userName = readlineSync.question('May I have your name? ');
console.log(`Hello, ${userName}!`);
console.log(gameDescription);
for (let i = 0; i < attemptsNum; i += 1) {
const gameData = genGameData();
const question = car(gameData);
const correctAnswer = cdr(gameData);
console.log(`Question: ${question}`);
const userAnswer = readlineSync.question('Your answer: ');
if (correctAnswer !== userAnswer) {
console.log(`"${userAnswer}" is wrong answer ;(. Correct answer was "${correctAnswer}"`);
console.log(`Lets try again, ${userName}!`);
return;
}
console.log('Correct!');
}
console.log(`Congratulations, ${userName}!`);
};