Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add task solution #2351

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
67 changes: 66 additions & 1 deletion src/makeRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,73 @@
*
* @return {Robot}
*/

const evacuateCoords = {
x: 1400,
y: 500,
};

function makeRobot(name, wheels, version) {
// write code here
return {
name,
wheels,
version,
coords: {
x: 0,
y: 0,
},
get info() {

Choose a reason for hiding this comment

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

Suggested change
get info() {
get info() {

return `name: ${name}, chip version: ${version}, wheels: ${wheels}`;
Copy link

Choose a reason for hiding this comment

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

let's use 'this' here
If you will create a function to change these variables later - it will not work as expected without 'this'

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

Choose a reason for hiding this comment

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

add gaps here


goLeft(step = 1) {
if (step < 1) {
return this;
}

this.coords.x -= step;

return this;
Copy link

Choose a reason for hiding this comment

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

think on how you can refactor it to get rid of double 'return this' statement

},

goRight(step = 1) {
if (step < 1) {
return this;
}

this.coords.x += step;

return this;
},

goForward(step = 1) {
if (step < 1) {
return this;
}

this.coords.y += step;

return this;
},

goBack(step = 1) {
if (step < 1) {
return this;
}

this.coords.y -= step;

return this;
},

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

module.exports = makeRobot;
Loading