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

Solution #318

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

Solution #318

wants to merge 3 commits into from

Conversation

Hladkyi03
Copy link

No description provided.

Copy link

@DarkMistyRoom DarkMistyRoom left a comment

Choose a reason for hiding this comment

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

Good job! Let's improve it a bit

let randomNumber = '';
const previousNumbers = [];

for (let i = 0; i < 4;) {

Choose a reason for hiding this comment

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

why don't you use increment here?

Comment on lines 10 to 29
let randomNumber = '';
const previousNumbers = [];

for (let i = 0; i < 4;) {
const randomNum = Math.floor(Math.random() * 10);

if (randomNum === 0 && i === 0) {
continue;
}

if (previousNumbers.includes(randomNum)) {
continue;
}

previousNumbers.push(randomNum);
randomNumber += randomNum.toString();
i++;
}

return +randomNumber;

Choose a reason for hiding this comment

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

Suggested change
let randomNumber = '';
const previousNumbers = [];
for (let i = 0; i < 4;) {
const randomNum = Math.floor(Math.random() * 10);
if (randomNum === 0 && i === 0) {
continue;
}
if (previousNumbers.includes(randomNum)) {
continue;
}
previousNumbers.push(randomNum);
randomNumber += randomNum.toString();
i++;
}
return +randomNumber;
let res = '';
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (let i = 0; i < 4; i++) {
const index = Math.floor(Math.random() * (10 - i));
res += numbers.splice(index, 1)[0];
}
return res;

src/app.js Outdated
if (checkIsValidUserInput(number)) {
userInput = number;
} else {
terminal.write('Invalid input\n');

Choose a reason for hiding this comment

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

would be great to specify what the user has done wrong. You can do it inside the validation function

src/app.js Outdated
userInput = number;
} else {
terminal.write('Invalid input\n');
askForNumber().then(resolve);

Choose a reason for hiding this comment

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

no need to use additional resolve here

@Hladkyi03
Copy link
Author

Your code for generating number dont pass 2 tests, so i didnt use it. Improved validation function, now it gives certain information whats wrong. Also changed a bit asdForNumber function and i need both resolves, if i remove one of them the program will not work with wrong input

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

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

The previous mentor's comments were not fixed

@Hladkyi03
Copy link
Author

What didnt fixed? I wrote a message, where explained all details, if u provide a comment u should describe what i need to do

Copy link

@vadiimvooo vadiimvooo left a comment

Choose a reason for hiding this comment

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

Please check comments and fix the code.

src/app.js Outdated
userInput = number;
resolve();
} else {
askForNumber().then(resolve);

Choose a reason for hiding this comment

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

You should remove redundant then chain

Comment on lines 10 to 29
let randomNumber = '';
const previousNumbers = [];

for (let i = 0; i < 4;) {
const randomNum = Math.floor(Math.random() * 10);

if (randomNum === 0 && i === 0) {
continue;
}

if (previousNumbers.includes(randomNum)) {
continue;
}

previousNumbers.push(randomNum);
randomNumber += randomNum.toString();
i++;
}

return +randomNumber;

Choose a reason for hiding this comment

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

This block can be modified in the next way

Suggested change
let randomNumber = '';
const previousNumbers = [];
for (let i = 0; i < 4;) {
const randomNum = Math.floor(Math.random() * 10);
if (randomNum === 0 && i === 0) {
continue;
}
if (previousNumbers.includes(randomNum)) {
continue;
}
previousNumbers.push(randomNum);
randomNumber += randomNum.toString();
i++;
}
return +randomNumber;
function generateRandomNumber() {
const secretCode = Array.from({ length: 4 }, (el) => 'x');
for (let i = 0; i < secretCode.length; i++) {
secretCode[i] = assignRandomNumber(secretCode);
}
return Number(secretCode.join(''));
}
const assignRandomNumber = (secretCode) => {
const number = Math.floor(Math.random() * 9 + 1);
if (secretCode.includes(number)) {
return assignRandomNumber(secretCode);
}
return number;
};

@Hladkyi03 Hladkyi03 requested a review from vadiimvooo February 4, 2024 10:14
Copy link

@maxim2310 maxim2310 left a comment

Choose a reason for hiding this comment

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

Well done

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.

5 participants