From f8ac4132c6daba8d3630588bda7f4ec57f587085 Mon Sep 17 00:00:00 2001 From: andrew gidrovich Date: Sun, 16 Jul 2023 13:07:41 +0300 Subject: [PATCH] add task solution --- src/makeRobot.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..d6d3d271 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,57 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + 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(steps = 1) { + this.coords.y += Math.max(steps, 0); + + return this; + }, + + goBack(steps = 1) { + this.coords.y -= Math.max(steps, 0); + + return this; + }, + + goLeft(steps = 1) { + this.coords.x -= Math.max(steps, 0); + + return this; + }, + + goRight(steps = 1) { + this.coords.x += Math.max(steps, 0); + + return this; + }, + + evacuate() { + this.coords = { + x: 1400, y: 500, + }; + + return this; + }, + }; + + return robot; } module.exports = makeRobot;