Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getDirection(direction) {
- let hor = 0;
- let ver = 0;
- switch (direction) {
- case ('forward'):
- hor = 0; ver = 1;
- break;
- case ('back'):
- hor = 0; ver = -1;
- break;
- case ('right'):
- hor = 1; ver = 0;
- break;
- case ('left'):
- hor = -1; ver = 0;
- break;
- case ('stop'):
- hor = 0; ver = 0;
- break;
- }
- return (`hor=${hor} ver=${ver}`);
- }
- console.log(getDirection('forward'));
- /*We train robots but teaching robots is even harder than teaching people!
- Our robot receives a command to its terminal in the form of the string back, forward, left, right, stop. Then his brain converts the value into x and y coordinates and sends an impulse with coordinates to its robotic legs as a string hor=x ver=y.
- Write a function getDirection, that takes a string direction with direction and returns a string in the format hor=x ver=y.
- The commands are the following:
- forward is the signal 0 for x and 1 for y
- back is the signal 0 for x and -1 for y
- right is the signal 1 for x and 0 for y
- left is the signal -1 for x and 0 for y
- stop is the signal 0 for x and 0 for y
- If the command is not recognized, x and y will be set to 0.
- And one more thing. Our robot has not yet learned conditional operators, so you have to use a switch case.
- For example:
- For the 'forward' command the robot needs coordinates in the format hor=0 ver=1
- And he doesn't know 'turn around' command, so the coordinates will be hor=0 ver=0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement