Have students draw a scalable smiley face through programming to motivate the importance of using variables.

  • Some students won’t ever want to use variables, but it’s important that they become comfortable with and understand the importance of them if they’re going to continue programming.
  • This activity uses a student’s desire to change their program over time to motivate variable use.
    • The visual nature of this activity provides clear motivation for why variables are a great and necessary tool.
    • However, this activity doesn’t motivate the use of global variables well because it uses variables in a very specific, singular context. As such, it doesn’t show students the value of a variable throughout the lifetime of a program.
  • Activity:
    • Provide students with starter code that produces the image of a smiley face without the mouth.
      • The starter code should contain a method that draws a smiley face with a variable determining the face size. This variable could be an argument passed into the method or a local variable.
        • The code for the eyes and the circle will use this variable to determine their size.
      • Leave an empty space in the starter code where the students should write the code for the mouth.
        • Adding a comment that tells students where they are supposed to be writing their code can be helpful.
    • First, have students add to the program by programming a mouth centered horizontally on the face.
    • Next, have students resize the face.
      • Students should observe that without using a variable for scaling the face, the mouth they hardcoded will end up in the wrong place on the resized face.
        • Initially, students may want to manually reposition the mouth. Take this opportunity to show them how much faster and more efficiently they’ll be able to resize the face if they use variables in their program.

More about this tip

External Source
Interview with Pamela Fox
Other Tips By