From 55a7911af7212399731bd298d6f5fdda18094eff Mon Sep 17 00:00:00 2001 From: Dominika Karmel Date: Mon, 9 Oct 2023 12:20:47 +0200 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 4bcef1e45..5cd7a9561 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,64 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const COORDINATES_X = 1400; + const COORDINATES_Y = 500; + const robot = { + name, + wheels, + version, + coords: { + x: 0, + y: 0, + }, + + get info() { + return `name: ${name}, chip version: ${version}, wheels: ${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 = COORDINATES_X; + this.coords.y = COORDINATES_Y; + }, + }; + + return robot; } module.exports = makeRobot;