diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..698101611 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,63 @@ * @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(n = 1) { + if (n > 0) { + this.coords.y += n; + } + + return this; + }, + + goBack(n = 1) { + if (n > 0) { + this.coords.y -= n; + } + + return this; + }, + + goRight(n = 1) { + if (n > 0) { + this.coords.x += n; + } + + return this; + }, + + goLeft(n = 1) { + if (n > 0) { + this.coords.x -= n; + } + + return this; + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + }, + }; + + return robot; } module.exports = makeRobot;