-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created bulls and cows game #244
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
But your random number is generated every time you call the function. I think the main idea of the game is to guess a stable random number. (You just need to subtract the random number from the function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Do not change the source number on each user attempt.
src/app.js
Outdated
return; | ||
} | ||
|
||
const searchedNumber = generateNumber(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if user did not win, this number will be generated again and overwrite? In this case it is possible to win only by guessing all the numbers at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job!
src/app.js
Outdated
|
||
function gameStart() { | ||
terminal.question('Enter a number: ', (userInput) => { | ||
if (userInput.length !== 4 || !Number(userInput)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 is a magic value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fixed
src/app.js
Outdated
terminal.question('Enter a number: ', (userInput) => { | ||
if (userInput.length !== 4 || !Number(userInput)) { | ||
console.log('Invalid number, please enter a 4 different digits'); | ||
terminal.question('Enter a number: ', gameStart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
terminal.question('Enter a number: ', gameStart); | |
gameStart(); |
src/checkAnswer.js
Outdated
|
||
const userNumberArr = userNumber.split(''); | ||
|
||
for (let i = 0; i < 4; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 is a magic value
src/checkAnswer.js
Outdated
if (searchedNumber.includes(userNumberArr[i])) { | ||
if (searchedNumber.indexOf(userNumberArr[i]) === i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to use nested if
src/checkAnswer.js
Outdated
} | ||
} | ||
|
||
return [bulls, cows]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to return object
So when you do destructuring order doesn't matter
src/numberGenerator.js
Outdated
'use strict'; | ||
|
||
function generateNumber() { | ||
return Math.floor(1000 + Math.random() * 9000).toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small question below
src/app.js
Outdated
|
||
function gameStart() { | ||
terminal.question('Enter a number: ', (userInput) => { | ||
if (userInput.length !== 4 || !Number(userInput)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fixed
src/app.js
Outdated
return; | ||
} | ||
|
||
const [bulls, cows] = checkAnswer(searchedNumber, userInput); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work correctly now? You return object, not array
No description provided.