-
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
080067f
commit b2bbd29
Showing
9 changed files
with
92 additions
and
111 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,5 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import startGame from '../games/even.js'; | ||
import isItEven from '../games/even.js'; | ||
|
||
startGame(); | ||
isItEven(); |
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,5 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import maxGeneralDivider from '../games/gcd.js'; | ||
import isMaxGeneralDivider from '../games/gcd.js'; | ||
|
||
maxGeneralDivider(); | ||
isMaxGeneralDivider(); |
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,5 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import progression from '../games/progression.js'; | ||
import getProgression from '../games/progression.js'; | ||
|
||
progression(); | ||
getProgression(); |
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
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,26 +1,16 @@ | ||
import readlineSync from 'readline-sync'; | ||
import game from '../index.js'; | ||
|
||
import getRandomInt from '../function/getRandomInt.js'; | ||
|
||
const isEvenNum = (number) => number % 2 === 0; | ||
|
||
const startGame = () => { | ||
console.log('Welcome to the Brain Games!'); | ||
const userName = readlineSync.question('May I have your name? '); | ||
console.log(`Hello, ${userName}!`); | ||
console.log('Answer "yes" if the number is even, otherwise answer "no".'); | ||
for (let i = 0; i < 3; i += 1) { | ||
const number = getRandomInt(100); | ||
console.log('Question: ', number); | ||
const answerCorrect = isEvenNum(number) ? 'yes' : 'no'; | ||
const answerUser = readlineSync.question('Your answer: '); | ||
if (answerUser !== answerCorrect) { | ||
console.log(`'${answerUser}' is wrong answer ;(. Correct answer was '${answerCorrect}'.`); | ||
console.log("Let's try again, ", userName); | ||
return; | ||
} | ||
console.log('Correct!'); | ||
} | ||
console.log('Congratulations,', userName, '!'); | ||
const playEven = () => { | ||
const question = String(getRandomInt(100)); | ||
const answerCorrect = isEvenNum(question) ? 'yes' : 'no'; | ||
return [question, answerCorrect]; | ||
}; | ||
export default startGame; | ||
const isItEven = () => { | ||
const condition = ('Answer "yes" if the number is even, otherwise answer "no".'); | ||
game(playEven, condition); | ||
}; | ||
export default isItEven; |
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
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,31 +1,28 @@ | ||
import readlineSync from 'readline-sync'; | ||
|
||
import greetGamer from '../src/cli.js'; | ||
|
||
import getRandomInt from '../function/getRandomInt.js'; | ||
|
||
const isNumPrime = (num) => { | ||
if (num === 1) { | ||
return 'no'; | ||
import game from '../index.js'; | ||
|
||
const isNumPrime = (value) => { | ||
const num = Number(value); | ||
if (num === 1 || num === 0) { | ||
return false; | ||
} | ||
for (let i = 2; i < value; i += 1) { | ||
if (num % i === 0) { | ||
return false; | ||
} | ||
} | ||
return (num % 2 === 0 || num % 3 === 0) ? 'no' : 'yes'; | ||
return true; | ||
}; | ||
|
||
const playPrime = () => { | ||
const question = String(getRandomInt(100)); | ||
const answerCorrect = isNumPrime(question) ? 'yes' : 'no'; | ||
return [question, answerCorrect]; | ||
}; | ||
|
||
const isItPrime = () => { | ||
const userName = greetGamer(); | ||
console.log('Answer "yes" if given number is prime. Otherwise answer "no".'); | ||
for (let i = 0; i < 3; i += 1) { | ||
const number = getRandomInt(100); | ||
console.log('Question: ', number); | ||
const answerCorrect = isNumPrime(number); | ||
const answerUser = readlineSync.question('Your answer: '); | ||
if (answerUser !== answerCorrect) { | ||
console.log(`'${answerUser}' is wrong answer ;(. Correct answer was '${answerCorrect}'.`); | ||
console.log("Let's try again, ", userName); | ||
return; | ||
} | ||
console.log('Correct!'); | ||
} | ||
console.log('Congratulations,', userName, '!'); | ||
const condition = ('Answer "yes" if given number is prime. Otherwise answer "no".'); | ||
game(playPrime, condition); | ||
}; | ||
export default isItPrime; |
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
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,23 @@ | ||
import readlineSync from 'readline-sync'; | ||
|
||
import greetGamer from './src/cli.js'; | ||
|
||
const game = (partGame, condition) => { | ||
const userName = greetGamer(); | ||
console.log(condition); | ||
for (let i = 0; i < 3; i += 1) { | ||
const [question, answerCorrect] = partGame(); | ||
console.log('Question: ', question); | ||
const answerUser = readlineSync.question('Your answer: '); | ||
if (answerUser === String(answerCorrect)) { | ||
console.log('Correct!'); | ||
} else { | ||
console.log(`'${answerUser}' is wrong answer ;(. Correct answer was '${answerCorrect}'.`); | ||
console.log("Let's try again, ", userName); | ||
return; | ||
} | ||
} | ||
console.log('Congratulations,', userName, '!'); | ||
}; | ||
|
||
export default game; |