From c44e348ea100e03e10c93adde09a67e8a89d393d Mon Sep 17 00:00:00 2001 From: LukashevychSergey Date: Sat, 24 Feb 2024 19:36:27 +0200 Subject: [PATCH] add task solution --- src/makeRobot.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..a5bdff426 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,62 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const x = 0; + const y = 0; + + return { + name, + wheels, + version, + coords: { + x, y, + }, + + get info() { + const nameInfo = `name: ${this.name}`; + const versionInfo = `chip version: ${this.version}`; + const wheelsInfo = `wheels: ${this.wheels}`; + + return `${nameInfo}, ${versionInfo}, ${wheelsInfo}`; + }, + get location() { + return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; + }, + goForward(steps = 1) { + if (steps > 0) { + this.coords.y += steps; + } + + return this; + }, + goBack(steps = 1) { + if (steps > 0) { + this.coords.y -= steps; + } + + return this; + }, + goRight(steps = 1) { + if (steps > 0) { + this.coords.x += steps; + } + + return this; + }, + goLeft(steps = 1) { + if (steps > 0) { + this.coords.x -= steps; + } + + return this; + }, + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + + return this; + }, + }; } module.exports = makeRobot;