Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew17752985 committed Jul 16, 2023
1 parent 9dd4651 commit f8ac413
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/makeRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,57 @@
* @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(steps = 1) {
this.coords.y += Math.max(steps, 0);

return this;
},

goBack(steps = 1) {
this.coords.y -= Math.max(steps, 0);

return this;
},

goLeft(steps = 1) {
this.coords.x -= Math.max(steps, 0);

return this;
},

goRight(steps = 1) {
this.coords.x += Math.max(steps, 0);

return this;
},

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

return this;
},
};

return robot;
}

module.exports = makeRobot;

0 comments on commit f8ac413

Please sign in to comment.