From aed87f66c2c8282b99c3fc928ab790aa9267d170 Mon Sep 17 00:00:00 2001 From: Anastasia Len Date: Sat, 4 Nov 2023 14:37:15 -0400 Subject: [PATCH] added implementation --- src/makeRobot.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..7bde1f22 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,63 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + return { + name: name, + wheels: wheels, + version: 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(step = 1) { + if (step > 0) { + this.coords.y += step; + } + + return this; + }, + + goBack(step = 1) { + if (step > 0) { + this.coords.y -= step; + } + + return this; + }, + + goLeft(step = 1) { + if (step > 0) { + this.coords.x -= step; + } + + return this; + }, + + goRight(step = 1) { + if (step > 0) { + this.coords.x += step; + } + + return this; + }, + + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + + return this; + }, + }; } module.exports = makeRobot;