Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ly-manka
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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');

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.

@@ -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];

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.

let number = '';

for (let i = 0; i < 4; i++) {
const randomIndex = Math.floor(Math.random() * vailableDigits.length);

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.

const randomDigit = vailableDigits[randomIndex];

number = number.concat(randomDigit);
vailableDigits.splice(randomIndex, 1);

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.

Comment on lines 27 to 33
if (userNumbers.includes(number)) {
if (userNumbers.indexOf(number) === i) {
bullsAndCows.bulls += 1;
} else {
bullsAndCows.cows += 1;
}
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants