From d75d8acae74732e809e58701a53a8a0a4d5103f9 Mon Sep 17 00:00:00 2001 From: divamal Date: Thu, 17 Aug 2023 16:14:04 +0300 Subject: [PATCH] Solution --- src/makeRobot.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..02a626872 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,56 @@ * @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; + }, + + goRight(steps = 1) { + this.coords.x += Math.max(steps, 0); + + return this; + }, + + goLeft(steps = 1) { + this.coords.x -= Math.max(steps, 0); + + return this; + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + + return this; + }, + }; + + return robot; } module.exports = makeRobot;