-
Notifications
You must be signed in to change notification settings - Fork 538
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
add bulls and cows game #432
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.
Great job on implementing the Bulls and Cows game! 🎉 The core functionality is working well, and your code meets the task requirements. There are a few minor improvements you could consider: correcting the typo in vailableDigits
to availableDigits
, refining the error message for clarity, and ensuring the logic for counting cows doesn't overlap with bulls. Keep up the good work and happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
src/app.js
Outdated
promptUser(); | ||
} | ||
} else { | ||
console.log('Number should include 4 uniq digits from 1 to 9'); |
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.
The error message could be more specific. Consider changing it to: 'Number should include 4 unique digits from 1 to 9.' This makes it clear that the digits must be unique and within the specified range.
src/modules/generateRandomNumber.js
Outdated
@@ -7,7 +7,19 @@ | |||
* @return {number} A random 4-digit number | |||
*/ | |||
function generateRandomNumber() { | |||
/* Write your code here */ | |||
const digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |||
const vailableDigits = [...digits]; |
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.
There is a typo in the variable name vailableDigits
. It should be corrected to availableDigits
for clarity and to prevent potential errors.
src/modules/generateRandomNumber.js
Outdated
let number = ''; | ||
|
||
for (let i = 0; i < 4; i++) { | ||
const randomIndex = Math.floor(Math.random() * vailableDigits.length); |
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.
Ensure that the typo in vailableDigits
is corrected to availableDigits
here as well.
src/modules/generateRandomNumber.js
Outdated
const randomDigit = vailableDigits[randomIndex]; | ||
|
||
number = number.concat(randomDigit); | ||
vailableDigits.splice(randomIndex, 1); |
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.
Ensure that the typo in vailableDigits
is corrected to availableDigits
here as well.
src/modules/getBullsAndCows.js
Outdated
if (userNumbers.includes(number)) { | ||
if (userNumbers.indexOf(number) === i) { | ||
bullsAndCows.bulls += 1; | ||
} else { | ||
bullsAndCows.cows += 1; | ||
} | ||
} |
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.
The current logic may incorrectly count a digit as a cow even if it has already been counted as a bull. Consider using separate loops or a mechanism to track which digits have been counted as bulls to prevent them from being counted as cows.
No description provided.