Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Your NameNatalia committed Nov 3, 2023
1 parent 9dd4651 commit ca9b88f
Showing 1 changed file with 54 additions and 1 deletion.
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() {
const robotName = `name: ${this.name}, `;
const robotInfo = `chip version: ${this.version}, wheels: ${this.wheels}`;

return robotName + robotInfo;
},
get location() {
return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`;
},
goForward(steps = 1) {
if (steps > 0) {
this.coords.y += steps;
}

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

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

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

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

return this;
},

};

return robot;
}

module.exports = makeRobot;

0 comments on commit ca9b88f

Please sign in to comment.