Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasia-Bernada committed Aug 11, 2023
1 parent 9dd4651 commit e73973c
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/makeRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,62 @@
* @return {Robot}
*/
function makeRobot(name, wheels, version) {
// write code here
const objRobot = {
name,
wheels,
version,
coords: {
x: 0,
y: 0,
},

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

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;
},

get info() {
return `name: ${name}, chip version: ${version}, wheels: ${wheels}`;
},

get location() {
return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`;
},
};

return objRobot;
}

module.exports = makeRobot;

0 comments on commit e73973c

Please sign in to comment.