Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions src/makeRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,66 @@
* @return {Robot}
*/
function makeRobot(name, wheels, version) {
// write code here
}
const serviceCenterX = 1400;
const serviceCenterY = 500;
Comment on lines +41 to +42

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static constants are usually named uppercase.

Suggested change
const serviceCenterX = 1400;
const serviceCenterY = 500;
const SERVICE_CENTER_X = 1400;
const SERVICE_CENTER_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;
},

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

return robot;
}
module.exports = makeRobot;