From ecf8fb746dd3b16fd872f3d2abbf2710f3588733 Mon Sep 17 00:00:00 2001 From: Anna Kovnatska Date: Sun, 17 Sep 2023 18:16:58 -0500 Subject: [PATCH] make robots --- src/makeRobot.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..19dff4bb5 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -39,6 +39,68 @@ */ function makeRobot(name, wheels, version) { // write code here + const robot = { + name, + wheels, + version, + coords: { + x: 0, + y: 0, + }, + + goRight(step = 1) { + if (step > 0) { + this.coords.x += step; + } + + return this; + }, + + goLeft(step = 1) { + if (step > 0) { + this.coords.x -= step; + } + + return this; + }, + + goForward(step = 1) { + if (step > 0) { + this.coords.y += step; + } + + return this; + }, + + goBack(step = 1) { + if (step > 0) { + this.coords.y -= step; + } + + return this; + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + + return `x:${this.coords.x} , y: ${this.coords.y}`; + }, + + get info() { + const robotName = `name: ${this.name}, `; + const robotVersion = `chip version: ${this.version}, `; + const robotWheels = `wheels: ${this.wheels}`; + + return robotName + robotVersion + robotWheels; + }, + + get location() { + return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; + }, + }; + + return robot; } module.exports = makeRobot;