-
Notifications
You must be signed in to change notification settings - Fork 530
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
Den
committed
Oct 13, 2024
1 parent
b9eb4f1
commit bc54c03
Showing
6 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -27,5 +27,8 @@ | |
}, | ||
"mateAcademy": { | ||
"projectType": "javascript" | ||
}, | ||
"dependencies": { | ||
"readline": "^1.3.0" | ||
} | ||
} |
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,3 +1,38 @@ | ||
/* eslint-disable max-len */ | ||
/* eslint-disable no-console */ | ||
'use strict'; | ||
|
||
// Write your code here | ||
const readline = require('readline'); | ||
const { checkIsValidUserInput } = require('./modules/checkIsValidUserInput'); | ||
const { getBullsAndCows } = require('./modules/getBullsAndCows'); | ||
const { generateRandomNumber } = require('./modules/generateRandomNumber'); | ||
|
||
const terminal = readline.createInterface(process.stdin, process.stdout); | ||
|
||
const randomNumber = generateRandomNumber(); | ||
|
||
const askForInput = () => { | ||
terminal.question('Enter a number of 4 different digits: ', (number) => { | ||
if (!checkIsValidUserInput(String(number))) { | ||
console.log( | ||
'Invalid input. Please enter a 4-digit number with unique digits that does not start with 0.', | ||
); | ||
|
||
return askForInput(); // Запрашиваем ввод снова | ||
} | ||
|
||
console.log(`Your input: ${number}`); | ||
|
||
const { bulls, cows } = getBullsAndCows(+number, randomNumber); | ||
|
||
if (bulls === 4) { | ||
console.log('you win'); | ||
terminal.close(); | ||
} else { | ||
console.log(`Bulls: ${bulls}, Cows: ${cows}`); | ||
askForInput(); // Запрашиваем ввод снова | ||
} | ||
}); | ||
}; | ||
|
||
askForInput(); |
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
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