Skip to content

Commit

Permalink
I refracted the code
Browse files Browse the repository at this point in the history
  • Loading branch information
OPTIMISTIXX committed Jul 28, 2023
1 parent 67fbf1a commit 8af15b9
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/makeRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,31 @@ function makeRobot(name, wheels, version) {
return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`;
},
goForward(distance = 1) {
if (distance < 0) {
return this;
if (distance > 0) {
this.coords.y += distance;
}

this.coords.y += distance;

return this;
},
goBack(distance = 1) {
if (distance < 0) {
return this;
if (distance > 0) {
this.coords.y -= distance;
}

this.coords.y -= distance;

return this;
},
goRight(distance = 1) {
if (distance < 0) {
return this;
if (distance > 0) {
this.coords.x += distance;
}

this.coords.x += distance;

return this;
},
goLeft(distance = 1) {
if (distance < 0) {
return this;
if (distance > 0) {
this.coords.x -= distance;
}

this.coords.x -= distance;

return this;
},
evacuate() {
Expand Down

0 comments on commit 8af15b9

Please sign in to comment.