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
55 changes: 54 additions & 1 deletion src/makeRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,60 @@
* @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) {
Comment on lines +73 to +80

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add empty line between methods

if (step > 0) {
this.coords.x -= step;
}

return this;
},

evacuate() {
this.coords.y = 500;
this.coords.x = 1400;
},
};

return Robot;
}

module.exports = makeRobot;