From 0e104d570b210e8dc113b327ea931b7794181790 Mon Sep 17 00:00:00 2001 From: Maciej Kujawa Date: Fri, 28 Jul 2023 19:56:56 +0200 Subject: [PATCH] solution --- src/makeRobot.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..95b4909a 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,61 @@ * @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}`; + }, + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + }, + + goForward(steps = 1) { + if (steps > 0) { + this.coords.y += steps; + } + + return this; + }, + goBack(steps = 1) { + if (steps > 0) { + this.coords.y -= steps; + } + + return this; + }, + goLeft(steps = 1) { + if (steps > 0) { + this.coords.x -= steps; + } + + return this; + }, + goRight(steps = 1) { + if (steps > 0) { + this.coords.x += steps; + } + + return this; + }, + }; + + return robot; } +// goForward, goBack, goRight, goLeft + module.exports = makeRobot;