-
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
Solution #433
base: master
Are you sure you want to change the base?
Solution #433
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.
Thank you for your hard work on the 'Bulls & Cows' game! 🎉 While your implementation is mostly correct, there are a few critical issues that need to be addressed to ensure the game functions as intended.
-
Random Number Generation: The logic for generating a 4-digit number with unique digits needs improvement. Currently, it may produce numbers with fewer than 4 digits or with leading zeros. Please adjust the logic to ensure the number is always 4 digits long, with the first digit non-zero and all digits unique.
-
User Input Handling: When the input is invalid, the program should not proceed to calculate bulls and cows. Instead, it should prompt the user to try again. Adding a
return
statement after displaying the invalid input message will help in preventing further execution and allow the user to input again.
Once these issues are resolved, your code will be ready for approval. Keep up the great work, and I'm confident you'll nail these changes! 💪
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/app.js
Outdated
if (!checkIsValidUserInput(text)) { | ||
stdout.write(INVALID_INPUT_MESSAGE); | ||
} |
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.
Currently, if the input is invalid, the program only writes an error message but does not return or prompt the user to input again. You should add a return
statement after writing the INVALID_INPUT_MESSAGE
to prevent further execution of the code block and prompt the user to try again.
src/modules/generateRandomNumber.js
Outdated
const uniqRandomNumbers = new Set(); | ||
|
||
while (uniqRandomNumbers.size !== 4) { | ||
const randomNumber = Math.floor(1 + Math.random() * 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 current logic for generating random numbers only produces digits from 1 to 9. This ensures no leading zero, but the logic for ensuring exactly 4 unique digits is flawed. Consider modifying the logic to ensure the first digit is non-zero and the remaining digits are unique, potentially by generating the first digit separately and then filling the rest.
src/modules/generateRandomNumber.js
Outdated
uniqRandomNumbers.add(randomNumber); | ||
} | ||
|
||
return Number(Array.from(uniqRandomNumbers).join('')); |
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 conversion of the set to a number may result in fewer than 4 digits if the set contains leading zeros. Ensure that the number is always 4 digits long by adjusting the logic to handle leading zeros appropriately.
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.
Review Summary
Great job on implementing the 'Bulls & Cows' game! 🎉 Your code is mostly correct, but there are a couple of critical issues that need attention to ensure the game functions as intended:
-
Random Number Generation: The
generateRandomNumber
function is designed to create a 4-digit number with unique digits. However, due to the unordered nature of sets, the current logic might not always produce a valid 4-digit number. Consider using an array to maintain the order of digits and ensure the first digit is always non-zero. -
User Input Handling: In
app.js
, the program currently continues execution even when the user input is invalid. To prevent this, add areturn
statement after displaying the invalid input message. This will ensure that the user is prompted to input again without proceeding to calculate bulls and cows.
These improvements are crucial for the functionality of the game. Addressing them will enhance the user experience and ensure the game operates correctly.
Remember, the decision to approve your pull request is to help you move forward with your learning journey. Please review the comments and make the necessary changes to improve your code. Keep up the good work, and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
if (!checkIsValidUserInput(text)) { | ||
stdout.write(INVALID_INPUT_MESSAGE + PROMPT_MESSAGE); | ||
} |
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.
To prevent the program from proceeding with invalid input, add a return
statement after displaying the invalid input message. This will ensure that the user is prompted to input again without calculating bulls and cows.
digits.add(randomDigit); | ||
} | ||
|
||
return Number(Array.from(digits).join('')); |
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 implementation may not guarantee a 4-digit number due to the unordered nature of sets. Consider using an array to maintain the order of digits and ensure the first digit is always non-zero.
Implemented solution