From cf73987c1e0b09f7c2308cd0fc20d9709ddd533a Mon Sep 17 00:00:00 2001 From: M DD Date: Wed, 9 Aug 2023 16:43:26 +0300 Subject: [PATCH] js_task_make_robot solution v1 --- src/makeRobot.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..95e9fbd5 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,60 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const robot = { + get info() { + return `name: ${name}, chip version: ${version}, wheels: ${wheels}`; + }, + + get location() { + return `${name}: x=${this.coords.x}, y=${this.coords.y}`; + }, + + goRight(times = 1) { + if (times < 0) { + return this; + } + this.coords.x = this.coords.x + 1 * times; + + return this; + }, + goLeft(times = 1) { + if (times < 0) { + return this; + } + this.coords.x = this.coords.x - 1 * times; + + return this; + }, + goBack(times = 1) { + if (times < 0) { + return this; + } + this.coords.y = this.coords.y - 1 * times; + + return this; + }, + goForward(times = 1) { + if (times < 0) { + return this; + } + this.coords.y = this.coords.y + 1 * times; + + return this; + }, + + 'coords': { + x: 0, + y: 0, + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + }, + }; + + return robot; } module.exports = makeRobot;