Lesson 7: Envelope Variables

Overview

Variables are used as placeholders for values such as numbers or words. Variables allow for a lot of freedom in programming. Instead of having to type out a phrase many times or remember an obscure number, computer scientists can use variables to reference them. This lesson helps to explain what variables are and how we can use them in many different ways. The idea of variables isn't an easy concept to grasp, so we recommend allowing plenty of time for discussion at the end of the lesson.

Purpose

Variables are very helpful in programming. Students will be introduced to this topic using envelopes to represent variables that have been given names. The value of the variable will be written on a card inside of an envelope. This lesson helps students understand how names can be a placeholder for values in the physical world, so that programming with variables will seem less confusing in the virtual world.

Agenda

Warm Up (10 min)

Main Activity (20 min)

Wrap Up (10 min)

Assessment (10 min)

Extended Learning

View on Code Studio

Objectives

Students will be able to:

  • Identify variables and determine their values.
  • Define and call variables in the context of real-life activities.
  • Create situations which require the use of variables.

Preparation

  • Obtain 6 or more blank envelopes for warm up plus some for the main activity.
  • Print one worksheet per student.
  • Print one assessment for each student.
  • Provide students with envelopes, paper, pens & pencils.
  • Make sure every student has a journal.

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Teachers

For the Students

Vocabulary

  • Variable - A label for a piece of information used in a program.

Support

Report a Bug

Teaching Guide

Warm Up (10 min)

Vocabulary

This lesson has one important word:

  • Variable - Say it with me: Vayr-ee-ah-buhl

A placeholder for a piece of information that can change.

Introduction

Call four volunteers to the front of the room and line them up. Let the students know that you are going to write a poem for each of them.

On the board (or under your document camera) write the sentence for your first student (suppose it's Bill):

"My student Bill, standing proud
is a fine example for the crowd"

Encourage the students to clap at your abilities and thank Bill for volunteering. Allow Bill to sit down (or go to the back of the line) as you erase the board, then call the next volunteer (we'll say that she's called Annie).

"My student Annie, standing proud
is a fine example for the crowd"

Again, accepting applause, erase the board and invite the next volunteer.

"My student Jenny, standing proud
is a fine example for the crowd"

As you call the final volunteer, inquire as to whether everyone in the class would like a poem written about each of them. Maybe the everyone in the whole school? Goodness, that's going to take a while! Pose the question to your students:

"How could I do this more quickly?"

Your students will likely pick up on the fact that only one word is changing, and that word is simply a person's name. Help them see the location by circling Jenny's name on the board and writing "firstName" next to it.

"It would take a long time to write a poem for everyone in the school if I couldn't start until I knew who I was writing it about, wouldn't it?"

  • How long do you think it would take to make a video game if they couldn't start until they knew your username?
  • How expensive would video games be if they had to be created separately for each person?
  • How do you think we can get around that?

By this time, it's quite likely that your class will come up with the idea of having a placeholder. With that, they're most of the way into understanding where this lesson goes.

  • What would we call that placeholder?
    • We need to call it something that makes sense. We wouldn't want to call it "age" if it was a placeholder for their name, right?

Now, let's add some more volunteers. Give them each a piece of paper to write their name on, and have them tuck it inside individual envelopes labeled firstName.

This time, put the poem on the board with a blank space labeled "firstName" where the student's name will go.

  • Have the first student in line (likely the last student from the previous example) pull their name from the envelope and that's what you'll write in the space.
  • When you erase the board, only erase the portion with the last student's name in it.
  • Call the next student to show their variable.
  • Repeat as many times as is entertaining

Now it's time for the main activity.

Main Activity (20 min)

Envelope Variables - Worksheet

Once the students understand how the envelopes relate to the sentences, pass out the activity worksheet and let them prepare some variables of their own.

Directions:

  • Divide students into groups of 2-4.
  • Have students design (draw) a robot.
  • After 10-15 minutes, request that the students fill their envelopes with important details about their robot such as its name, height, and purpose.
  • Collect each group's envelopes, then bring them to the front of the room to share.
  • Write on the board, "My robot's name is robotName, it is numUnitsTall tall, and it's purpose is purpose."
  • Use the envelopes to fill the appropriate variable in the sentence, then ask each group to stand when they hear the sentence that describes their creation.

Wrap Up (10 min)

Flash Chat: What did we learn?

  • What did we learn today?
  • Can you think of anywhere that you have seen variables before?
  • There is at least one variable at the top of most homework hand outs? Can you think of what it could be?
  • Why do you think that professionals do not put spaces in variable names?
    • What would happen if there was a variable "eye" a variable "color" and a variable "eye color"?
  • Variables can be used to store numbers, too.
    • Suppose I have envelopes labeled num1 and num2, then I write num1+num2?
    • What happens if the "num1" envelope contains the number 4 and "num2" contains the number 5?

Journaling

Having students write about what they learned, why it’s useful, and how they feel about it can help solidify any knowledge they obtained today and build a review sheet for them to look to in the future.

Journal Prompts:

  • What was today's lesson about?
  • How do you feel about today's lesson?
  • What is a variable?
  • Why do you think variables are important in programming?

Assessment (10 min)

Envelope Variables - Assessment

Allow students enough time to finish this assessment. If you are willing to spare more time, go over the answers as a class.

Extended Learning

Use these activities to enhance student learning. They can be used as outside of class activities or other enrichment.

What's in the box?

  • Draw boxes on a piece of paper with simple mathematical operators between them.
    • For instance [] + [] = []
  • Have similar size squares with numbers between 1 & 20.
  • Ask one student to come create a true equation, using the numbers provided.
  • Once the student has finished (and the class verifies the equation) exchange one of the numbers with another one, then remove a second number entirely.
    • Tell the students that there is a hidden number in the empty box that makes that equation true again.
    • What number is in the box?
  • Play this game over and over again until you can remove the number from any location and the students can figure out what it is supposed to be.
  • Levels
  • 1
  • (click tabs to see student view)
View on Code Studio

Student Instructions

Envelope Variables

Variables allow for a lot of freedom in computer science. This lesson helps to explain what variables are and how we can use them in many different ways.

Standards Alignment

View full course alignment

CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
  • 1B-AP-09 - Create programs that use variables to store and modify data.