-
Notifications
You must be signed in to change notification settings - Fork 530
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
base: master
Are you sure you want to change the base?
Develop #225
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.
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(' ')); |
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.
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'); |
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.
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++) { |
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.
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.
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.
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]) { |
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 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); |
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.
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++) { |
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.
still not fixed
const checkedNumberFromRandom = checkedNumbers(randomNum, number); | ||
const checkedBull = checkedNumberFromRandom.filter(item => item === 'bull'); | ||
|
||
if (checkedBull.length === 4) { |
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.
4 is a 'magic number' so makes sense to move it to the variable
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 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.
.
No description provided.