PencilCoder

Variables!

Goals:

  • Use variables to store values, make code more readable, and to simplify code maintenance.

Coding Snippets:

  • coding snippets
  • The statement x=0 creates a variable called x that is assigned the value 0. If x already existed, this statement would update x with the value 0.
  • The statement x=x+1 would be invalid in math class, but makes perfect sense here. It means: add 1 to the current value of x, then save that result as x.
  • pause makes the turtle wait the given number of seconds before subsequent instructions are executed.
  • The cs function clears all graphics except the turtle.

Math and Computer Concepts:

  • Variables are holding tanks for information. These holding tanks are called variables because their content can vary, or change.
  • In Coffeescript, as in most coding languages, the equal sign does not test for equality. Rather, it assigns the value of the expression on the right to the variable on the left.
  • The examples below illustrate how variables can be used to simplify code and facilitate code maintenance. Both snippets trace out a hexagon. However, the code on the right more clearly shows the logic of our work. Additionally, to change it to another polygon, all you need to do is change one number!
Blank space

Activities:

Save all programs for today's class in a folder called Variables. Use variables and loops in each activity.