diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..b4b0d1e2 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,68 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const EVACUATE_CORD_X = 1400; + const EVACUATE_CORD_Y = 500; + + const robot = { + name, + wheels, + version, + + coords: { + x: 0, + y: 0, + }, + + evacuate() { + this.coords.x = EVACUATE_CORD_X; + this.coords.y = EVACUATE_CORD_Y; + }, + + 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(step = 1) { + if (step > 0) { + this.coords.y += step; + } + + return this; + }, + + goBack(step = 1) { + if (step > 0) { + this.coords.y -= step; + } + + return this; + }, + + goRight(step = 1) { + if (step > 0) { + this.coords.x += step; + } + + return this; + }, + + goLeft(step = 1) { + if (step > 0) { + this.coords.x -= step; + } + + return this; + }, + }; + + return robot; } module.exports = makeRobot;