File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+ import readlineSync from 'readline-sync' ;
3+
4+ //приветствие
5+ console . log ( 'Welcome to the Brain Games!' ) ;
6+ const userName = readlineSync . question ( 'May I have your name? ' ) ;
7+ console . log ( `Hello, ${ userName } !` ) ;
8+
9+ //поясняем смысл
10+ console . log ( 'Answer "yes" if the number is even, otherwise answer "no".' ) ;
11+
12+ //цикл подсчета
13+ let correctAnswersCount = 0 ;
14+
15+ while ( correctAnswersCount < 3 ) {
16+ //получаем число от 1 до 100
17+ let getRandomNumber = Math . floor ( Math . random ( ) * 100 ) + 1 ;
18+ //выводим число
19+ console . log ( 'Question: ' + getRandomNumber ) ;
20+ //получаем ответ пользователя
21+ let getAnswer = readlineSync . question ( 'Your answer: ' ) ;
22+
23+ //проверяем четность
24+ const checkEvenness = ( number ) => {
25+ return number % 2 === 0 ? 'yes' : 'no' ; // Возвращаем 'yes', если четное, иначе 'no'
26+ } ;
27+
28+ // Получаем правильный ответ
29+ const correctAnswer = checkEvenness ( getRandomNumber ) ;
30+ //сравниваем ответы
31+ if ( getAnswer === correctAnswer ) {
32+ console . log ( 'Correct!' ) ;
33+ correctAnswersCount ++ ;
34+ // Проверяем, достигли ли мы 3 правильных ответа
35+ if ( correctAnswersCount === 3 ) {
36+ console . log ( `Congratulations, ${ userName } !` ) ;
37+ //закрываем цикл
38+ break ;
39+ }
40+ } else {
41+ console . log ( `Answer "${ getAnswer } " if the number is even, otherwise answer "${ correctAnswer } ".` ) ;
42+ //закрываем цикл
43+ break ;
44+ }
45+ } ;
46+
Original file line number Diff line number Diff line change 2323 "homepage" : " https://github.com/elrbkn/qa-auto-engineer-javascript-project-44#readme" ,
2424 "dependencies" : {
2525 "readline-sync" : " ^1.4.10"
26+ "lodash" : " ^4.6.2"
2627 },
28+ },
2729 "devDependencies" : {
2830 "@eslint/js" : " ^9.14.0" ,
2931 "babel-eslint" : " ^10.1.0" ,
You can’t perform that action at this time.
0 commit comments