Robot Arm Activity

The javascript on this page implements a simulated robot arm as described in the activity based on Exercise 4 in Chapter 3 of your text, with some parts of the code missing. You fill in the missing parts correctly to get the program to work.

Recall that commands for the robot arm are as follows:

N move in a straight line one unit toward the top of the paper ("North")
S move one unit toward the bottom ("South")
E move one unit to the right ("East")
W move one unit to the left ("West")
U lift pen from paper ("Up", stop writing)
D lower pen to paper ("Down", start writing with next move)
H lift pen and move to top left corner ("Home")

The code below, with the missing sections filled in correctly, has been tested using Google Chrome and Internet Explorer 10.x. It will work in Chrome, but not in IE 10, because IE 10 does not support the HTML canvas tag. The code has not been checked in IE 11, the most recent version.

The questions in this activity are limited to features in the code that relate closely to concepts covered in class. You should find the javascript code for the missing parts of the program to be very similar, if not identical, to the pseudocode presented in your text. If you want to learn more about javascript and how it is used in web pages, a good source of information is http://www.w3schools.com/.

After downloading this file from Moodle, you should first change the extension from .txt to .html so it will open as a web page in your web browser. Each of the missing sections of code you must fill in to get the robot arm simulation to work are signified by the placeholder "@@@". Note, the length of the missing sectins varies, and bears no relation to the length of the placeholder.

The extension for this file has already been changed to htm and the correct code for each of the placeholders inserted in accordance with the instructions above. To view the original lines with the placeholders, now commented out, and additional comments on how to input instructions and use the other interactive features, look at the source for this page.

Robot drawing area:

x: y:

Your browser does not support the HTML5 canvas tag.

Input robot drawing arm instructions:

Input delta x:

Input delta y: