Kojo explorations/Commands and programs

This activity involves the following:
 * Learning about commands, actions, and programs.
 * Learning to draw lines using the turtle.
 * Learning the clear, forward, and right commands.
 * Exploring the ideas of unit length, distances, and right angles, and using them to make a square geometrical figure.
 * Using the Kojo error recovery feature.

Step 1
Type in the following code within the Script Editor and run it: Q1a) What does the turtle do? Does it move? By how much? In what direction?

Step 2
Clear the line made on the Drawing Canvas in the previous step by right-clicking on the Canvas and pressing Clear. Then delete the text in the script editor by pressing the Clear Editor toolbar button. Now type in the following code and run it:

Q2a) What do you think the showAxes command does? Does it show you the unit of length (called a pixel) used for drawing on the turtle canvas? 10

Q2b) What do you think the forward command does? What does the input to the command specify? The input to the forward command is the number that you write within round brackets after the command, e.g., forward(100) has 100 as its input.

Note – when you are asked to figure out what a command does, feel free to fire up a Kojo Scratchpad (using the File -> New Kojo Scratchpad menu item) to experiment with different inputs to the command. A Kojo Scratchpad is an instance of Kojo for doing “rough work” and figuring out things – as you work on an activity inside Kojo.

Note – The Turtle Commands Quickref chapter contains descriptions of commonly used turtle commands. You should go over to that chapter and validate your understanding of a command after you figure out what it does.

Step 3
Clear the Drawing Canvas and Script Editor. Then type in the following code and run it:

Q3a What do you think the right command does?

Step 4
Clear the Script Editor (but not the drawing canvas). Then type in the following code and run it:

Q4a) What does the clear command do?

Step 5
Clear the Script Editor. Then type in the following code and run it. But first guess (before running the code) what figure is made by this program:

Q5a) How is it useful to have the clear command as the first line of your program?

Step 6
Clear the Script Editor. Then type in the following incorrect code and run it:

Q6a) What does Kojo tell you (in the output pane)? Observe the kind of message that Kojo shows you when you give it an incorrect command to run.

Q6b) Using this message, can you determine (and go to) the line in your program that has the problem? Hint – click on Locate error in script in the Output pane.

Self Exploration
Play with the clear, forward, and right commands before you move on to the exercise. Deliberately make a few mistakes (misspelled commands, missing round-brackets) and then try to fix the mistakes with the help of the Kojo error messages.

Theory
A program is a series of instructions for the computer.

These instructions can be of a few different kinds. The first kind of instruction (the kind that you have seen in this activity) is a command. A command makes the computer carry out an action (like moving the turtle forward) or indirectly affects future actions (like setting the pen color).

Actions are effects produced by your program that you can see, hear, etc. They result in outputs from your program.

Commands can take inputs. These inputs let you control what the command does, e.g., the input to the forward command lets you control the length of the line that the turtle draws. A command with no inputs always does exactly the same thing.

Exercise
Write a program to make the following figure: Sides of the square – length = 100 pixels.