From e86103f275d673743734e17de36b2b734f4bab75 Mon Sep 17 00:00:00 2001 From: Roman Perepelkin Date: Fri, 18 Aug 2023 15:27:32 +0300 Subject: [PATCH 1/3] Solution --- src/makeRobot.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..3facb377b 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,76 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here -} + const robot = { + goRight: goRight, + goLeft: goLeft, + goForward: goForward, + goBack: goBack, + evacuate: evacuate, + + coords: { + 'x': 0, + 'y': 0, + }, + + get info() { + return `name: ${this.name}, chip version: ${this.version},` + + ` wheels: ${this.wheels}`; + }, + + get location() { + return `${this.name}: x=${robot.coords['x']}, y=${robot.coords['y']}`; + }, + }; + + robot.name = name; + robot.wheels = wheels; + robot.version = version; + + function goRight(step = 1) { + if (step < 0) { + return robot; + } + robot.coords['x'] += step; + + return robot; + } + + function goLeft(step = 1) { + if (step < 0) { + return robot; + } + robot.coords['x'] -= step; + + return robot; + } + + function goForward(step = 1) { + if (step < 0) { + return robot; + } + robot.coords['y'] += step; + + return robot; + } + + function goBack(step = 1) { + if (step < 0) { + return robot; + } + robot.coords['y'] -= step; + + return robot; + } + + function evacuate() { + robot.coords['x'] = 1400; + robot.coords['y'] = 500; + + return robot.coords; + } + + return robot; +}; module.exports = makeRobot; From 3248e665cefd08bcf9528eb42c5324c52c5b7bc1 Mon Sep 17 00:00:00 2001 From: Roman Perepelkin Date: Mon, 21 Aug 2023 10:07:50 +0300 Subject: [PATCH 2/3] Solution --- src/makeRobot.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 3facb377b..8c5219245 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -45,6 +45,10 @@ function makeRobot(name, wheels, version) { goBack: goBack, evacuate: evacuate, + name, + wheels, + version, + coords: { 'x': 0, 'y': 0, @@ -60,10 +64,6 @@ function makeRobot(name, wheels, version) { }, }; - robot.name = name; - robot.wheels = wheels; - robot.version = version; - function goRight(step = 1) { if (step < 0) { return robot; From 894124fdd1ccaf756b98dbc034cb328b035c77e3 Mon Sep 17 00:00:00 2001 From: Roman Perepelkin Date: Wed, 23 Aug 2023 14:01:43 +0300 Subject: [PATCH 3/3] Solution --- src/makeRobot.js | 76 +++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 8c5219245..eb60e70c4 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -39,19 +39,13 @@ */ function makeRobot(name, wheels, version) { const robot = { - goRight: goRight, - goLeft: goLeft, - goForward: goForward, - goBack: goBack, - evacuate: evacuate, - name, wheels, version, coords: { - 'x': 0, - 'y': 0, + x: 0, + y: 0, }, get info() { @@ -60,52 +54,48 @@ function makeRobot(name, wheels, version) { }, get location() { - return `${this.name}: x=${robot.coords['x']}, y=${robot.coords['y']}`; + return `${this.name}: x=${robot.coords.x}, y=${robot.coords.y}`; }, - }; - function goRight(step = 1) { - if (step < 0) { - return robot; - } - robot.coords['x'] += step; + goRight(step = 1) { + if (step > 0) { + this.coords.x += step; + } - return robot; - } + return this; + }, - function goLeft(step = 1) { - if (step < 0) { - return robot; - } - robot.coords['x'] -= step; + goLeft(step = 1) { + if (step > 0) { + this.coords.x -= step; + } - return robot; - } + return this; + }, - function goForward(step = 1) { - if (step < 0) { - return robot; - } - robot.coords['y'] += step; + goForward(step = 1) { + if (step > 0) { + this.coords.y += step; + } - return robot; - } + return this; + }, - function goBack(step = 1) { - if (step < 0) { - return robot; - } - robot.coords['y'] -= step; + goBack(step = 1) { + if (step > 0) { + this.coords.y -= step; + } - return robot; - } + return this; + }, - function evacuate() { - robot.coords['x'] = 1400; - robot.coords['y'] = 500; + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; - return robot.coords; - } + return this.coords; + }, + }; return robot; };