From eee5a3f9ddb445e684908c39bbd7322a0195d5d0 Mon Sep 17 00:00:00 2001 From: Karpets Sofia Date: Sun, 6 Aug 2023 21:36:14 +0300 Subject: [PATCH] solution --- src/makeRobot.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..95fe6367 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,64 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const SERVICE_CENTER_COORDINATES = { + x: 1400, + 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 = 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 = SERVICE_CENTER_COORDINATES.x; + this.coords.y = SERVICE_CENTER_COORDINATES.y; + }, + }; + + return robot; } module.exports = makeRobot;