Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana-js committed Oct 6, 2023
1 parent 929d405 commit 3995dc7
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
Binary file added .DS_Store
Binary file not shown.
28 changes: 14 additions & 14 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
env:
node: true
es2021: true
extends:
- 'airbnb-base'
parserOptions:
ecmaVersion: latest
sourceType: module
rules:
no-console: 0
import/extensions:
- error
- ignorePackages
- js: always
# env:
# node: true
# es2021: true
# extends:
# - 'airbnb-base'
# parserOptions:
# ecmaVersion: latest
# sourceType: module
# rules:
# no-console: 0
# import/extensions:
# - error
# - ignorePackages
# - js: always

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ brain-games:

publish:
npm publish --dry-run

lint:
npx eslint .
npx eslint .

brain-even:
node bin/brain-even.js
41 changes: 41 additions & 0 deletions bin/brain-even.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import readlineSync from 'readline-sync';


const isEvenNum = () => {
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;
}
}
};
isEvenNum();
export default isEvenNum;
2 changes: 2 additions & 0 deletions bin/brain-games.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

import greetGamer from '../src/cli.js';
import isEvenNum from './brain-even.js';

greetGamer();

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"version": "1.0.0",
"description": "[![Actions Status](https://github.com/Tanya14081981/frontend-project-44/workflows/hexlet-check/badge.svg)](https://github.com/Tanya14081981/frontend-project-44/actions)",
"bin": {
"brain-games": "bin/brain-games.js"
"brain-games": "bin/brain-games.js",
"brain-even": "bin/brain-even.js"
},
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ console.log('Welcome to the Brain Games!');
const greetGamer = () => {
const name = readlineSync.question('May I have your name?');
console.log(`Hello, ${name}!`);
return name;
};
export default greetGamer;

0 comments on commit 3995dc7

Please sign in to comment.