From 04b6b3bc757dac89350bede53dc29584fec03d67 Mon Sep 17 00:00:00 2001 From: Kriss Kozak Date: Sat, 19 Aug 2023 17:38:03 +0300 Subject: [PATCH] Make robot --- src/makeRobot.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e4..fdeebbf9 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,49 @@ * @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(steps = 1) { + this.coords.y += steps > 0 ? steps : 0; + + return this; + }, + goBack(steps = 1) { + this.coords.y -= steps > 0 ? steps : 0; + + return this; + }, + goRight(steps = 1) { + this.coords.x += steps > 0 ? steps : 0; + + return this; + }, + goLeft(steps = 1) { + this.coords.x -= steps > 0 ? steps : 0; + + return this; + }, + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + + return this; + }, + }; } module.exports = makeRobot;