Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
bogemna committed Aug 6, 2023
1 parent 9dd4651 commit eee5a3f
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion src/makeRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,64 @@
* @return {Robot}
*/
function makeRobot(name, wheels, version) {
// write code here
const SERVICE_CENTER_COORDINATES = {
x: 1400,
y: 500,
};

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 = SERVICE_CENTER_COORDINATES.x;
this.coords.y = SERVICE_CENTER_COORDINATES.y;
},
};

return robot;
}

module.exports = makeRobot;

0 comments on commit eee5a3f

Please sign in to comment.