From 74e565702c61068b3b1a60ddf4f875f079dffe1d Mon Sep 17 00:00:00 2001 From: Andrii Nakonechnyi Date: Sun, 6 Aug 2023 15:50:30 +0300 Subject: [PATCH 1/2] js_task_make_robot --- src/makeRobot.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..4ee1b744 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,68 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const robot = { + name, + wheels, + version, + coords: { + x: 0, + y: 0, + }, + + get info() { + return ( + `name: ${name}, chip version: ${version}, wheels: ${wheels}` + ); + }, + + get location() { + return ( + `${name}: x=${this.coords.x}, y=${this.coords.y}` + ); + }, + + goForward(step = 1) { + if (step > 0) { + this.coords.y += step; + } + + return this; + }, + + goBack(step = 1) { + if (step > 0) { + this.coords.y -= step; + } + + return this; + }, + + goRight(step = 1) { + if (step > 0) { + this.coords.x += step; + } + + return this; + }, + + goLeft(step = 1) { + if (step > 0) { + this.coords.x -= step; + } + + return this; + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + + return this; + }, + }; + + return robot; } module.exports = makeRobot; From 4683abf8d9d2c1a6eb0528e1dde577e365f71375 Mon Sep 17 00:00:00 2001 From: Andrii Nakonechnyi Date: Sun, 6 Aug 2023 21:56:00 +0300 Subject: [PATCH 2/2] js_task_make_robot-added_this --- src/makeRobot.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4ee1b744..3c962c75 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -37,6 +37,10 @@ * * @return {Robot} */ + +const EVACUATION_COORDS_X = 1400; +const EVACUATION_COORDS_Y = 500; + function makeRobot(name, wheels, version) { const robot = { name, @@ -49,13 +53,13 @@ function makeRobot(name, wheels, version) { get info() { return ( - `name: ${name}, chip version: ${version}, wheels: ${wheels}` + `name: ${this.name}, chip version: ${this.version}, wheels: ${this.wheels}` ); }, get location() { return ( - `${name}: x=${this.coords.x}, y=${this.coords.y}` + `${this.name}: x=${this.coords.x}, y=${this.coords.y}` ); }, @@ -92,8 +96,8 @@ function makeRobot(name, wheels, version) { }, evacuate() { - this.coords.x = 1400; - this.coords.y = 500; + this.coords.x = EVACUATION_COORDS_X; + this.coords.y = EVACUATION_COORDS_Y; return this; },