Cobbled together toy robot.
How do I make an cobbled together toy robot.?
What is a cobbled together toy robot.? How do you make a cobbled together toy robot.? This script and codes were developed by Mei Weng Brough-Smyth on 06 November 2022, Sunday.
Cobbled together toy robot. - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Cobbled together toy robot.</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Cobbled together toy robot. - Script Codes JS Codes
var instructions = ['PLACE 1 2 0', 'MOVE', 'LEFT', 'LEFT', 'MOVE', 'RIGHT', 'MOVE', 'REPORT']
var robot = { x: 0, y: 0, f: 0
}
var orientations = { 0: 'NORTH', 1: 'WEST', 2: 'SOUTH', 3: 'EAST'
}
var place = function(x, y, f) { robot.x = x; robot.y = y; robot.f = f;
}
var move = function() { var orientation = orientations[robot.f]; switch (orientation) { case 'NORTH': robot.x++; break; case 'SOUTH': robot.x--; break; case 'EAST': robot.y--; break; case 'WEST': robot.y++; break; default: console.log("can't move that way dummy") }
}
var rotate = function(direction) { var currentDirection = robot.f; switch(direction) { case 'LEFT': var newDirection = currentDirection - 1; robot.f = checkDirection(newDirection); break; case 'RIGHT': var newDirection = currentDirection + 1; robot.f = checkDirection(newDirection); break; default: console.log('not legit') }
}
var checkDirection = function(newDirection) { switch(newDirection) { case -1: newDirection = 3; break; case 4: newDirection = 0; break; } return newDirection;
}
var report = function() { console.log("x:" + robot.x); console.log("y:" + robot.y); console.log("facing: " + orientations[robot.f]);
}
var processDirection = function(instructions) { instructions = instructions.split(' ') switch (instructions[0]) { case 'PLACE': place(instructions[1], instructions[2], instructions[3]) break; case 'MOVE': move(); break; case 'LEFT': rotate('LEFT'); break; case 'RIGHT': rotate('RIGHT'); break; case 'REPORT': report(); break; default: console.log('yea nuh') break; }
}
for (i = 0; i < instructions.length; i++) { processDirection(instructions[i]);
}
Home Page | Home |
Developer | Mei Weng Brough-Smyth |
Username | melatonind |
Uploaded | November 06, 2022 |
Rating | 3 |
Size | 1,903 Kb |
Views | 12,144 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Words to Colours | 2,363 Kb |
Simple Linear Regression with Editable Table | 3,264 Kb |
Twitch Follower | 2,345 Kb |
The Monty Hall Problem | 4,360 Kb |
Junk | 1,439 Kb |
Autocomplete | 1,670 Kb |
Find the AWS service you need right now | 2,634 Kb |
Word of the Day | 1,635 Kb |
New York Times Article Puller | 1,703 Kb |
Simple Linear Regression | 3,558 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Material design buttons | Fischaela | 4,381 Kb |
Ripples in water | Nobitagit | 2,704 Kb |
Reading Grid | Tappily | 4,306 Kb |
Long Shadow Button | Uixcrazy | 3,550 Kb |
Buttons for autumn | Nikazawila | 1,795 Kb |
Starfield using KineticJS | Asp | 3,512 Kb |
A Pen by Patrick Cox | Pcridesagain | 2,899 Kb |
Save for later... | Victorfreire | 1,359 Kb |
A Pen by Xand0r | Xand0r | 1,928 Kb |
Slider | Mohammed-fawzy | 2,634 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!