-
Notifications
You must be signed in to change notification settings - Fork 537
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
developed #434
base: master
Are you sure you want to change the base?
developed #434
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
'use strict'; | ||
|
||
// Write your code here | ||
const { checkIsValidUserInput } = require('./modules/checkIsValidUserInput'); | ||
const { generateRandomNumber } = require('./modules/generateRandomNumber'); | ||
const { getBullsAndCows } = require('./modules/getBullsAndCows'); | ||
|
||
const numberToGuess = generateRandomNumber(); | ||
const userInput = process.argv.slice(2).join(''); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(userInput); | ||
|
||
if (checkIsValidUserInput(userInput)) { | ||
getBullsAndCows(userInput, numberToGuess); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,17 @@ | |
* @return {number} A random 4-digit number | ||
*/ | ||
function generateRandomNumber() { | ||
/* Write your code here */ | ||
const digits = []; | ||
|
||
while (digits.length < 4) { | ||
const randomDigit = Math.floor(Math.random() * 10); | ||
|
||
if (!digits.includes(randomDigit) && randomDigit !== 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition |
||
digits.push(randomDigit); | ||
} | ||
} | ||
|
||
return parseInt(digits.join(''), 10); | ||
} | ||
|
||
module.exports = { | ||
|
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
getBullsAndCows
function expectsuserInput
to be a number, but it is currently a string. Consider convertinguserInput
to a number before passing it to the function, for example usingparseInt(userInput, 10)
.