diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..2c2c00a7e 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -1,11 +1,6 @@ 'use strict'; /** - * Mate Robot Factory impressed by your success, they are ready to accept - * you into the Tech team, you will learn to program robots together - * with the team! Are you in business As a test task, you will need to - * program our equipment that makes robots. - * * Create a makeRobot function that takes the string name and the number * wheels, version and returns the robot object. * The robot coming off the assembly line must be able to: @@ -38,7 +33,58 @@ * @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(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; + }, + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + }, + }; + + return robot; } module.exports = makeRobot;