Skip to content

Commit

Permalink
Merge pull request #12 from dzencot/features
Browse files Browse the repository at this point in the history
Features
  • Loading branch information
dzencot committed Jan 4, 2017
2 parents 2ec5e0c + 41c9b2b commit ce77a85
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ install:
run:
npm run babel-node -- ./bin/$(G)
lint:
npm run eslint ./bin/
npm run eslint ./bin/ ./src/
publish:
npm publish
7 changes: 5 additions & 2 deletions bin/brain-even.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env node
// @flow
/* eslint-disable no-console */

import readlineSync from 'readline-sync';
import oddGame from '../src/odd-game';

console.log('Welcome to the Brain Games!\n');
console.log('Welcome to the Brain Games!');
const name = readlineSync.question('May I have your name? ');
console.log(`Hello, '${name}'!`);
console.log(`Hello, '${name}'\n`);
oddGame(name);
27 changes: 27 additions & 0 deletions src/odd-game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow
/* eslint-disable no-console */

import readlineSync from 'readline-sync';

export default (nameUser) => {
const iter = (number, correctIter) => {
if (correctIter >= 3) {
console.log(`Congratulations, '${nameUser}'!`);
return 0;
}
console.log(`Question: '${number}'`);
const answer = readlineSync.question('Your answer: ');
const correctAnswer = number % 2 === 0 ? 'yes' : 'no';
if (answer === correctAnswer) {
console.log('Correct!');
const newCorrectIter = correctIter + 1;
const newNumber = newCorrectIter === 1 ? 6 : 15;
return iter(newNumber, newCorrectIter);
}
console.log(`'${answer}' is wrong answer ;(. Correct answer was '${correctAnswer}'.`);
console.log(`Let's try again, '${nameUser}'!`);
return iter(number, correctIter);
};
console.log('Answer "yes" if number odd otherwise answer "no"\n');
return iter(15, 0);
};

0 comments on commit ce77a85

Please sign in to comment.