From cf0c86c3d52ce38ea224614550334e10bb1fc36d Mon Sep 17 00:00:00 2001 From: Maria Snegireva Date: Wed, 9 Aug 2023 17:05:26 +0300 Subject: [PATCH 1/2] add task solution --- src/makeRobot.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..34c02b21 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,64 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here -} + return { + 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(value = 1) { + if (value < 0) { + return this; + } + this.coords.y += 1 * value; + + return this; + }, + + goBack(value = 1) { + if (value < 0) { + return this; + } + this.coords.y -= 1 * value; + return this; + }, + + goRight(value = 1) { + if (value < 0) { + return this; + } + this.coords.x += 1 * value; + + return this; + }, + + goLeft(value = 1) { + if (value < 0) { + return this; + } + this.coords.x -= 1 * value; + + return this; + }, + + evacuate() { + this.coords = { + x: 1400, y: 500, + }; + }, + }; +} module.exports = makeRobot; From 6c0b13e56a4dcaeaeca578e412de43557f4c5092 Mon Sep 17 00:00:00 2001 From: Maria Snegireva Date: Wed, 9 Aug 2023 18:10:01 +0300 Subject: [PATCH 2/2] add task solution --- src/makeRobot.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 34c02b21..a437a5a2 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -56,37 +56,33 @@ function makeRobot(name, wheels, version) { }, goForward(value = 1) { - if (value < 0) { - return this; + if (value > 0) { + this.coords.y += 1 * value; } - this.coords.y += 1 * value; return this; }, goBack(value = 1) { - if (value < 0) { - return this; + if (value > 0) { + this.coords.y -= 1 * value; } - this.coords.y -= 1 * value; return this; }, goRight(value = 1) { - if (value < 0) { - return this; + if (value > 0) { + this.coords.x += 1 * value; } - this.coords.x += 1 * value; return this; }, goLeft(value = 1) { - if (value < 0) { - return this; + if (value > 0) { + this.coords.x -= 1 * value; } - this.coords.x -= 1 * value; return this; },