-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4b5e66
commit 5494930
Showing
1 changed file
with
41 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |