|
1 | 1 | import readlineSync from 'readline-sync'; |
2 | 2 | const getRandomNum = (min, max) => Math.floor(Math.random() * (max - min + 1) + min); |
3 | 3 | const needAnswers = 3 |
4 | | -const TheMotor = (feature, description) => { |
| 4 | +function TheMotor(feature, description) { |
5 | 5 | console.log('Welcome to the Brain Games!'); |
6 | 6 | const name = readlineSync.question('May I have your name? '); |
7 | 7 | console.log(`Hello, ${name}!`); |
8 | 8 | console.log(description); |
9 | | - for (let i = 1; i <= correctAnswers; i += 1) { |
10 | | - const [exp, rightAnswer] = feature(); |
11 | | - console.log(`Question: ${exp} `); |
12 | | - const userAnswer = readlineSync.question('Your Answer: '); |
13 | | - if (userAnswer !== rightAnswer) { |
14 | | - console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${rightAnswer}'. \nLet's try again, ${name}!`); |
15 | | - return; |
16 | | - } |
17 | | - console.log('Correct!'); |
18 | | - if (i === needAnswers) { |
19 | | - console.log(`Congratulations, ${name}!`); |
20 | | - return; |
21 | | - } |
| 9 | + for (let i = 1; i <=needAnswers, i+=1){ |
| 10 | + const [exp, rightAnswer] = feature(); |
| 11 | + console.log(`Question: ${exp} `); |
| 12 | + const userAnswer = readlineSync.question('Your Answer: '); |
| 13 | + if (userAnswer !== rightAnswer) { |
| 14 | + console.log(`'${userAnswer}' is wrong answer ;(. Correct answer was '${rightAnswer}'. \nLet's try again, ${name}!`); |
| 15 | + return; |
| 16 | + } |
| 17 | + console.log('Correct!'); |
| 18 | + if (i === needAnswers) { |
| 19 | + console.log(`Congratulations, ${name}!`); |
| 20 | + return; |
| 21 | + } |
22 | 22 | } |
23 | | - }; |
| 23 | +} |
24 | 24 | const alert = '"yes" if the number is even, otherwise answer "no".'; |
25 | 25 | const Game = ()=>{ |
26 | 26 | const minNum = 1; |
27 | 27 | const maxNum = 1000; |
28 | 28 | const randomNum = getRandomNum(minNum, maxNum); |
29 | 29 | const rightAnswer = randomNum % 2 === 0 ? 'yes' : 'no'; |
30 | | - const coll = [randomNum, rightAnswer]; |
31 | | - return coll; |
| 30 | + return [randomNum, rightAnswer]; |
32 | 31 |
|
33 | 32 | } |
34 | 33 | const gameven = () =>{ |
|
0 commit comments