Skip to content

Commit 07ea37c

Browse files
index.js refactoring
1 parent f7e46c6 commit 07ea37c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import readlineSync from 'readline-sync';
2-
3-
const playGame = (questiongame, questionRound) => {
2+
// приветствие и имя
3+
const greetUser = () => {
44
console.log('Welcome to the Brain Games!');
55
const name = readlineSync.question('May I have your name? ');
6-
console.log(`Hello,${name}!`); // приветствие и имя
6+
console.log(`Hello,${name}!`);
7+
return name;
8+
};
9+
10+
const playGame = (questiongame, questionRound) => {
11+
const greeting = greetUser();
712
console.log(questiongame); // вывод вопроса игры
813
// цикл игры = 3
914
let i = 1;
@@ -16,7 +21,7 @@ const playGame = (questiongame, questionRound) => {
1621
// вывод неправильного ответа
1722
const wrong = () => {
1823
console.log(
19-
`'${answer}' is wrong answer ;(. Correct answer was '${correctAnsw}'.\nLet's try again, ${name}!`
24+
`'${answer}' is wrong answer ;(. Correct answer was '${correctAnsw}'.\nLet's try again, ${greeting}!`
2025
);
2126
};
2227
// проверка
@@ -28,7 +33,7 @@ const playGame = (questiongame, questionRound) => {
2833
i += 1;
2934
}
3035

31-
console.log(`Congratulations, ${name}!`);
36+
console.log(`Congratulations, ${greeting}!`);
3237
};
3338

3439
export default playGame;

0 commit comments

Comments
 (0)