From e73973cdc4138e7f84df2728f2963f4e0c4fe04e Mon Sep 17 00:00:00 2001 From: Anastasia Bernada Date: Fri, 11 Aug 2023 20:52:13 +0300 Subject: [PATCH] Solution --- src/makeRobot.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..981cc211 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,62 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const objRobot = { + name, + wheels, + version, + coords: { + x: 0, + y: 0, + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + }, + + 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; + }, + + get info() { + return `name: ${name}, chip version: ${version}, wheels: ${wheels}`; + }, + + get location() { + return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; + }, + }; + + return objRobot; } module.exports = makeRobot;