From 81e44157e51fcc15eede16e89ff1b51186daf751 Mon Sep 17 00:00:00 2001 From: Olena Nimakova Date: Wed, 13 Sep 2023 18:39:40 +0300 Subject: [PATCH] makeRobot task --- src/makeRobot.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..9787f86d6 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,64 @@ * @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(value = 1) { + if (value >= 0) { + this.coords.y += value; + }; + + return this; + }, + + goBack(value = 1) { + if (value >= 0) { + this.coords.y -= value; + }; + + return this; + }, + + goRight(value = 1) { + if (value >= 0) { + this.coords.x += value; + }; + + return this; + }, + + goLeft(value = 1) { + if (value >= 0) { + this.coords.x -= value; + }; + + return this; + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + }, + }; + + return robot; } module.exports = makeRobot;