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 |
Simple Linear Regression | 3,558 Kb |
Random Array | 1,551 Kb |
Autocomplete | 1,670 Kb |
New York Times Article Puller | 1,703 Kb |
A Pen by Mei Weng Brough-Smyth | 2,429 Kb |
Simple Linear Regression with Editable Table | 3,264 Kb |
Junk | 1,439 Kb |
Hacker News 2 | 2,135 Kb |
Cobbled together toy robot. | 1,903 Kb |
Find the AWS service you need right now | 2,634 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 |
CSS Hover Effects | Alen | 3,613 Kb |
Ball Physics | Getsetbro | 3,149 Kb |
Basic HTML5 Structure | YuvarajTana | 1,289 Kb |
Project Euler Problem 17 | Bfillmer | 2,739 Kb |
Mapbox Directions with geolocation tracking | Pollardld | 5,827 Kb |
Fluid Grid 12 | Alexoliverwd | 2,309 Kb |
Bootstrap 4 Gridsystem Demo | Rivella50 | 1,535 Kb |
Blog Concept - Single Post | Marionebl | 9,603 Kb |
A bit of elegance | Hackthevoid | 9,095 Kb |
Scoreboard.js basic usage | Tbleckert | 1,733 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!