Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
polinavafik committed Oct 9, 2023
1 parent 42a7483 commit 2f88954
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ function startGame() {
console.log('I expect a 4 digit num, love');
console.log('fix your answer and try again');
console.log('------------------------------');
startGame();
} else {
const [bulls, cows] = getBullsAndCows(correctAnswer, userInput);

console.log('------------------------------');
console.log(`Bulls: ${bulls}; Cows: ${cows}.`);
console.log('------------------------------');
startGame();
return startGame();
}

const { bulls, cows } = getBullsAndCows(correctAnswer, userInput);

console.log('------------------------------');
console.log(`Bulls: ${bulls}; Cows: ${cows}.`);
console.log('------------------------------');

return startGame();
});
};

Expand Down
4 changes: 3 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

const MAX_LENGTH = 4;

module.exports = MAX_LENGTH;
module.exports = {
MAX_LENGTH,
};
5 changes: 4 additions & 1 deletion src/getBullsAndCows.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function getBullsAndCows(correctNumber, userNumber) {
}
}

return [bulls, cows];
return {
bulls,
cows,
};
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion src/getRandomNums.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const MAX_LENGTH = require('./constants');
const { MAX_LENGTH } = require('./constants');

function getRandomNum() {
return Math.floor(Math.random() * 9) + 1;
Expand Down

0 comments on commit 2f88954

Please sign in to comment.