Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana-js committed Oct 6, 2023
1 parent d4b5e66 commit 5494930
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions bin/brain-even.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
import readlineSync from 'readline-sync';
import greetGamer from '../src/cli.js';

// eslint-disable-next-line consistent-return
const isEvenNum = () => {
console.log('Answer "yes" if the number is even, otherwise answer "no".');
for (let i = 0; i <= 3; i += 1) {
const number = Math.floor(Math.random() * 100);
console.log(`Question: ${number}`);
const answer = readlineSync.question('Your answer:');
const name = greetGamer();
if (number % 2 === 0) {
const answerYes = 'Correct!';
const answerNo = `'no' is wrong answer ;(. Correct answer was 'yes'.\nLet\'s try again, ${name}!`;
switch (answer) {
case 'yes':
console.log(answerYes);
return true;
case 'no':
console.log(answerNo);
return false;
default:
console.log(answerNo);
return false;
}
} else if (number % 2 !== 0) {
const answerYes = `'yes' is wrong answer ;(. Correct answer was 'no'.\nLet\'s try again, ${name}!`;
const answerNo = 'Correct!';
switch (answer) {
case 'yes':
console.log(answerYes);
return false;
case 'no':
console.log(answerNo);
return true;
default:
console.log(answerNo);
return false;
let result;
do {
result = false;
for (let i = 0; i <= 3; i += 1) {
const number = Math.floor(Math.random() * 100);
console.log(`Question: ${number}`);
const answer = readlineSync.question('Your answer:');
const name = greetGamer();
if (number % 2 === 0) {
const answerYes = 'Correct!';
const answerNo = `'no' is wrong answer ;(. Correct answer was 'yes'.\nLet's try again, ${name}!`;
switch (answer) {
case 'yes':
console.log(answerYes);
result = true;
break;
case 'no':
console.log(answerNo);
result = false;
break;
default:
console.log(answerNo);
result = false;
}
} else if (number % 2 !== 0) {
const answerYes = `'yes' is wrong answer ;(. Correct answer was 'no'.\nLet's try again, ${name}!`;
const answerNo = 'Correct!';
switch (answer) {
case 'yes':
console.log(answerYes);
result = false;
break;
case 'no':
console.log(answerNo);
result = true;
break;
default:
console.log(answerNo);
result = false;
}
}
}
}
} while (result);
};
export default isEvenNum;

0 comments on commit 5494930

Please sign in to comment.