From 2f889549366f202a4d5e1a6e7685e8a3b1ca1512 Mon Sep 17 00:00:00 2001 From: Diana Honcharova Date: Mon, 9 Oct 2023 23:31:24 +0300 Subject: [PATCH] refactoring --- src/app.js | 16 +++++++++------- src/constants.js | 4 +++- src/getBullsAndCows.js | 5 ++++- src/getRandomNums.js | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/app.js b/src/app.js index 3f32d0b..bc737c6 100644 --- a/src/app.js +++ b/src/app.js @@ -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(); }); }; diff --git a/src/constants.js b/src/constants.js index 220e0f0..8547a27 100644 --- a/src/constants.js +++ b/src/constants.js @@ -2,4 +2,6 @@ const MAX_LENGTH = 4; -module.exports = MAX_LENGTH; +module.exports = { + MAX_LENGTH, +}; diff --git a/src/getBullsAndCows.js b/src/getBullsAndCows.js index f6677c6..6cda694 100644 --- a/src/getBullsAndCows.js +++ b/src/getBullsAndCows.js @@ -16,7 +16,10 @@ function getBullsAndCows(correctNumber, userNumber) { } } - return [bulls, cows]; + return { + bulls, + cows, + }; } module.exports = { diff --git a/src/getRandomNums.js b/src/getRandomNums.js index e39436f..e5fafac 100644 --- a/src/getRandomNums.js +++ b/src/getRandomNums.js @@ -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;