-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add task solution #2351
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
return `name: ${name}, chip version: ${version}, wheels: ${wheels}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use 'this' here |
||
}, | ||
get location() { | ||
return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.