-
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
5494930
commit 9119877
Showing
4 changed files
with
62 additions
and
56 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,50 +1,5 @@ | ||
import readlineSync from 'readline-sync'; | ||
import greetGamer from '../src/cli.js'; | ||
#!/usr/bin/env node | ||
|
||
const isEvenNum = () => { | ||
console.log('Answer "yes" if the number is even, otherwise answer "no".'); | ||
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; | ||
import isEvenNum from '../src/game.js'; | ||
|
||
isEvenNum(); |
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 |
---|---|---|
|
@@ -2,8 +2,4 @@ | |
|
||
import greetGamer from '../src/cli.js'; | ||
|
||
import isEvenNum from './brain-even.js'; | ||
|
||
greetGamer(); | ||
|
||
isEvenNum(); |
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,11 +1,14 @@ | ||
import readlineSync from 'readline-sync'; | ||
|
||
console.log('Welcome to the Brain Games!'); | ||
export const getName = () => { | ||
const name = readlineSync.question('May I have your name?'); | ||
return name; | ||
}; | ||
|
||
const greetGamer = () => { | ||
const name = readlineSync.question('May I have your name?'); | ||
console.log('Welcome to the Brain Games!'); | ||
const name = getName(); | ||
console.log(`Hello, ${name}!`); | ||
return name; | ||
}; | ||
|
||
export default greetGamer; |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import readlineSync from 'readline-sync'; | ||
import getName from './cli.js'; | ||
|
||
const isEvenNum = () => { | ||
console.log('Answer "yes" if the number is even, otherwise answer "no".'); | ||
let result; | ||
const name = getName(); | ||
do { | ||
result = false; | ||
for (let i = 0; i <= 2; i += 1) { | ||
const number = Math.floor(Math.random() * 100); | ||
console.log(`Question: ${number}`); | ||
const answer = readlineSync.question('Your answer:'); | ||
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(answerYes); | ||
result = false; | ||
} | ||
} | ||
} | ||
} while (result); | ||
return result; | ||
}; | ||
|
||
export default isEvenNum; |