Cobbled together toy robot.

Size
1,903 Kb
Views
12,144

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. Previews

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]);
}
Cobbled together toy robot. - Script Codes
Cobbled together toy robot. - Script Codes
Home Page Home
Developer Mei Weng Brough-Smyth
Username melatonind
Uploaded November 06, 2022
Rating 3
Size 1,903 Kb
Views 12,144
Do you need developer help for Cobbled together toy robot.?

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!

Mei Weng Brough-Smyth (melatonind) Script Codes
Create amazing marketing copy with AI!

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!