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. Use this activity before (or in conjunction with) the lesson on abstraction to really hit the idea home.
Getting Started - 10 minutes
Activity: Envelope Variables - 20 minutes
Wrap-up - 10 minutes
Assessment - 10 minutes
- 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
- Utilize teamwork to enrich creative game play
Materials, Resources and Prep
For the Student
- Blank Paper
- 3 envelopes per group that have been labeled: robotName, numUnitsTall, & purpose
- 1 Envelope Variables Worksheet per group
- Variables Assessment Worksheet
For the Teacher
- 6 or more blank envelopes for warm-up
- Print one Envelope Variables Worksheet per student
- Print one Variables Assessment Worksheet
- Provide students with envelopes (details above), paper, pens & pencils
Getting Started (10 min)
This is a great time to review the last lesson that you went through with your class. We suggest you alternate between asking questions of the whole class and having students talk about their answers in small groups.
Here are some questions that you can ask in review:
What did we do last time?
What do you wish we would have had a chance to do?
Did you think of any questions after the lesson that you want to ask?
What was your favorite part of the last lesson??
Finishing the review by asking about the students' favorite things helps to leave a positive impression of the previous exercise, increasing excitement for the activity that you are about to introduce.
This lesson has one important word to review:
Variable - Say it with me: Vayr-ee-ah-buhl
A placeholder for a piece of information that can change
Call 4 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 them. Maybe 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 you 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.
Activity: Envelope Variables (20 min)
Once the students understand how the envelopes relate to the sentences, pass out the Robot Variables activity and let them prepare some variables of their own.
1) Divide students into groups of 2-4.
2) Have students design (draw) a robot.
3) After 10-15 min, request that the students fill their envelopes with important details about their robot.
4) Collect each group's envelopes, then bring them to the front of the room to share
5) Write on the board, "My robot's name is robotName, it is numUnitsTall tall, and it's purpose is purpose."
6) 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)
- 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?
You can choose to do these as a class, or have the students discuss with an elbow partner and share.
- Do you remember the definition of the word "variable"?
"A four sided parallelogram"
"A placeholder for a piece of information that can change"
"The wheels on the bottom of chair legs"
Assessment (10 min)
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.
Connections and Background Information
ISTE Standards (formerly NETS) Satisfied by this Lesson Include:
- 1c. Use models and simulations to explore complex systems and issues
- 2d. Contribute to project teams to produce original works or solve problems
- 4b. Plan and manage activities to develop a solution or complete a project
- 6c. Troubleshoot systems and applications
The activities in this lesson support CSTA K-12 Computer Science Standards:
- CL.L2-03 Collaborate with peers, experts, and others using collaborative practices such as pair programming, working in project teams, and participating in group active learning activities
- CT.L1:6-01 Understand and use the basic steps in algorithmic problem-solving
- CT.L1:6-02 Develop a simple understanding of an algorithm using computer-free exercises
- CPP.L1:6-05 Construct a program as a set of step-by-step instructions to be acted out
Next-Gen Science Standards
- 3-5-ETS1-1 Define a simple design problem reflecting a need or a want that includes specified criteria for success and constraints on materials, time, or cost
Common Core Mathematical Practices
- 2. Reason abstractly and quantitatively
- 6. Attend to precision
- 7. Look for and make use of structure
- 8. Look for and express regularity in repeated reasoning
Common Core Language Arts Standards
- L.3.6 Acquire and use accurately grade-appropriate conversational, general academic, and domain-specific words and phrases, including those that signal spatial and temporal relationships
- L.4.6 Acquire and use accurately grade-appropriate general academic and domain-specific words and phrases, including those that signal precise actions, emotions, or states of being and that are basic to a particular topic
- L.5.6 Acquire and use accurately grade-appropriate general academic and domain-specific words and phrases, including those that signal contrast, addition, and other logical relationships