From 523de8f129682f9fefd7d4010371b267cd8fc2af Mon Sep 17 00:00:00 2001 From: Taras Kusiy Date: Wed, 2 Aug 2023 14:50:05 +0300 Subject: [PATCH 1/2] solution --- src/makeRobot.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..c78cfa9b 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,61 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const ROBOT_STEP = 1; + const ROBOT_EVACUATE_COORDINATS_X = 1400; + const ROBOT_EVACUATE_COORDINATS_Y = 500; + + const robot = { + name, + wheels, + version, + coords: { + x: 0, + y: 0, + }, + get info() { + return `name: ${this.name}, chip version: ${this.version},` + + ` wheels: ${this.wheels}`; + }, + + get location() { + return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; + }, + goForward(step = ROBOT_STEP) { + if (step > 0) { + this.coords.y += step; + } + + return this; + }, + goBack(step = ROBOT_STEP) { + if (step > 0) { + this.coords.y -= step; + } + + return this; + }, + goRight(step = ROBOT_STEP) { + if (step > 0) { + this.coords.x += step; + } + + return this; + }, + goLeft(step = ROBOT_STEP) { + if (step > 0) { + this.coords.x -= step; + } + + return this; + }, + evacuate() { + this.coords.x = ROBOT_EVACUATE_COORDINATS_X; + this.coords.y = ROBOT_EVACUATE_COORDINATS_Y; + }, + }; + + return robot; } module.exports = makeRobot; From 3c08fc3ef876e73c5f2d4b9d94f0091eccf8f9f6 Mon Sep 17 00:00:00 2001 From: Taras Kusiy Date: Sun, 6 Aug 2023 22:20:00 +0300 Subject: [PATCH 2/2] changed the variable name --- src/makeRobot.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index c78cfa9b..c0094003 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,7 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - const ROBOT_STEP = 1; + const DEFAULT_ROBOT_STEP = 1; const ROBOT_EVACUATE_COORDINATS_X = 1400; const ROBOT_EVACUATE_COORDINATS_Y = 500; @@ -58,28 +58,28 @@ function makeRobot(name, wheels, version) { get location() { return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; }, - goForward(step = ROBOT_STEP) { + goForward(step = DEFAULT_ROBOT_STEP) { if (step > 0) { this.coords.y += step; } return this; }, - goBack(step = ROBOT_STEP) { + goBack(step = DEFAULT_ROBOT_STEP) { if (step > 0) { this.coords.y -= step; } return this; }, - goRight(step = ROBOT_STEP) { + goRight(step = DEFAULT_ROBOT_STEP) { if (step > 0) { this.coords.x += step; } return this; }, - goLeft(step = ROBOT_STEP) { + goLeft(step = DEFAULT_ROBOT_STEP) { if (step > 0) { this.coords.x -= step; }