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

Develop #225

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

Develop #225

wants to merge 4 commits into from

Conversation

Ilia991
Copy link

@Ilia991 Ilia991 commented Aug 14, 2023

No description provided.

Copy link

@lerastarynets lerastarynets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start! Let's fix and improve your work a little bit)

src/app.js Outdated
terminalInput.close();
} else {
terminalInput.write(' ');
terminalInput.write(checkedNumberFromRandom.join(' '));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a newline character at the end of the printed number for better readability in the terminal.

const checkedBull = checkedNumberFromRandom.filter(item => item === 'bull');

if (checkedBull.length === 4) {
terminalInput.write('You win');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a newline character at the end of the win message for better readability in the terminal.

let checkedValue = false;
const randomNum = Math.ceil(Math.random() * 10000);

for (let i = 0; i < randomNum.length; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

randomNum is a number, not a string. You cannot use .length property or indexing on a number. Convert randomNum to a string before this line.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not fixed

src/random.js Outdated

for (let i = 0; i < randomNum.length; i++) {
for (let q = 0; q < randomNum.length; q++) {
if (randomNum[i] === randomNum[q]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if condition will always be true when i equals to q. You need to exclude the case when i equals to q.

src/random.js Outdated
}
}

return checkedValue ? random() : String(randomNum);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of checkedValue being true, you are calling random() again. This recursion can risk a stack overflow if a number with unique digits is not found in reasonable iterations.

let checkedValue = false;
const randomNum = Math.ceil(Math.random() * 10000);

for (let i = 0; i < randomNum.length; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not fixed

const checkedNumberFromRandom = checkedNumbers(randomNum, number);
const checkedBull = checkedNumberFromRandom.filter(item => item === 'bull');

if (checkedBull.length === 4) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 is a 'magic number' so makes sense to move it to the variable

Copy link

@VitaliyBodnar VitaliyBodnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link

@VitaliyBodnar VitaliyBodnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

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.

4 participants