Learning Portal

Our hands-on, comprehensive lesson plans span a range of levels. Browse our free STEM and coding learning resources.

Marty Image

2.17: What is a Variable?

60 Minutes

Lesson Overview

Learners will explore events, measurements and objects that change in terms of size, value or number over the course of a period of time. We say that things that change, vary. A variable is something we use to represent an amount, either when we are not absolutely sure what the amount is or when it can change.

Key vocabulary:
    Variables , Store , Values, Assign, Declare,

Content Sections

  • Learning Objectives
  • Warm-up
  • Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
  • Get Learning
    • Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
      Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
      Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
    • Time for Practice
    • Unknown block type "figure", please specify a serializer for it in the `serializers.types` prop
      Unknown block type "figure", please specify a serializer for it in the `serializers.types` prop
      Unknown block type "figure", please specify a serializer for it in the `serializers.types` prop
      Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
    • Cool Down
      • Extensions & Challenges
      • Extend
      • Support
        • Additional Reading
        • 2.17: What is a Variable?

          60 Minutes

          Lesson Overview

          Learners will explore events, measurements and objects that change in terms of size, value or number over the course of a period of time. We say that things that change, vary. A variable is something we use to represent an amount, either when we are not absolutely sure what the amount is or when it can change.

          Key vocabulary:
            Variables , Store , Values, Assign, Declare,
          • Strong understanding of arguments and loops; experience with conditional statements
          • iPad or Tablet with MartyBlocks
            • Marty the Robot v2
            • Marty Workbook
            • Tablets
            • Access to the MartyBlocks editor

          Learning Objectives

          • Describe what a variable is.
          • Say why some programs use variables.

          This lesson will involve Marty walking and might be best to have Marty on the ground for all code tests.

          Warm-up

          Share with the learners a recipe for making a cake, the video shows how to make a cake in a mug using a microwave. Some measurements use the customary, or imperial, measurement and some use metric. There is no need to focus on the measurement types, the important part is the numerical value of each measurement; however, this could lead to a discussion on conversion if it is appropriate. Each measurement shows onscreen as the video plays.

          As learners watch, have them record the values for the recipe in their workbooks. Once complete, have learners calculate how much of each ingredient would be needed for two or more cake cups, support learners with the calculations as needed, the goal is more about thinking how the recipe amounts will vary - when I have two cakes I will double the ingredients, when I have three cakes I will treble them - rather than the actual amount at the end - 2 x 3 = 6 or 1/2 x 3 = 1 1/2.

          After the learners have completed the table, ask them what the variable was. the number of cakes. Reinforce that the variable is the number of cakes by explaining that as it changes, the total ingredients change but the ingredients for each cake do not change. The focus is not to define independent and dependent variables in this lesson, just to compute the new values for the total quantity of each ingredient.

          Get Learning

          The second video shows the setup for a science experiment. It showcases the necessary materials for the experiment to run once. Instead of learners replicating the experiment and thinking how many of each material they would need, have them consider what parts of the experiment are variables.

          • Sugar, salt and water are the materials but they are not variables.
          • The quantity of the materials is the variables.
          • For water, the temperature is a variable.
          • The goal is not to predict which would let the ice melt more quickly but rather what can vary with the materials.

          Use the workbook to have learners record their thoughts about what part of this experiment could be a variable. The textbox contains all the materials and potential variables for the experiment. Learners need to put the words in the correct place on the page. The answers are included in the teacher guide.

          To explore this lesson further, in science, we strongly recommend you visit the Chaos and the Clutter website, here.

          The following video features Marty acting based on a variable. The variable counts the number of times a user taps a sprite in 10 seconds. Then, the program instructs Marty to take that many steps. This is more advanced than what learners will be creating but it is a good example of illustrating what a variable is, for Marty, the video below shows that the variable name is steps, this makes sense for this variable because the output will be Marty's steps. Encourage learners, when it comes to them declaring, or naming, their variables, to use a name that makes sense.

          Have learners share their observations at the end. The video has this program run twice so that learners can see that the number of steps and sprite taps have both changed. The transitions are only to give Marty more screen space when walking.

          After viewing this video, have learners record the values for the variables in their workbook.

          Below is the process of setting the code to have Marty walk based on the taps. In the video of Marty walking, the green flag was pressed after Marty took the first set of steps, which reset the variable. With this in mind, have learners think about what the value for the steps must have been before the sprite was tapped - the steps variable was assigned a value of 0 at the start of the program.

          Time for Practice

          Variables have their own section in the MartyBlocks environment. The image in the presentation (below) shows where to find the variable section and the purpose of two of the blocks.

          The following image shows what happens after tapping 'Make a variable'.

          After tapping OK, learners will see a new block called Value, which is set to 0 for just now.

          This video shows learners how to find the variable section, and declare one for using with Marty, assign an initial value and change its value. This is a manual change rather than an automatic one, the earlier video of Marty walking had an automatic change.

          The video has no output through the physical Marty, the output is on the sprite Marty in MartyBlocks. The video stops before the green flag is pressed, have learners suggest what the Marty sprite will 'say' Discuss with learners what the output for a physical Marty could be: number of waves, kicks, steps, degrees for a movement, time taken for a movement, basically anything that is an argument in MartyBlocks for one of Marty's movements or looks.

          Learners need to have time to practice creating a variable and to plan for how the variable will affect Marty, setting a name for the variable and attaching this to an argument.

          Cool Down

          Bring learners back together to discuss the challenges they faced and overcame. Have groups model their creations and explain what is happening, when. Encourage other groups to ask questions to deepen their understanding of the processes.

          Suggested questions you might ask?

          • What values can you think of, in your daily life, that are variables? temperature, time, speed, distance, mass or weight, emotion, energy levels, etc.
          • What difference do you think there would be if there were no variables for recipes - think of different cakes that require different quantities of ingredients - more or less butter, sugar, salt? There would only be one recipe for cake: it would be a bit boring.
          • Which type of program do you think will be more interactive, one with or without variables? A program without variables will run the same way each time, there is, by default, no interactivity: you will not change the output of the program.

          Carry out any end of lesson routines.

          Log off devices and clear everything away.

          Extensions & Support

          Extend

          Challenge learners to trigger a second action with a conditional. A link can be drawn to different situations in mathematics when a certain value is reached: 5 in tally marks has a different way of recording, Roman Numerals change after 3 and then patterns emerge for new values, even numbers have the ones digit repeat after each 5 multiples, etc.

          Marty might take 13 steps but every 5th step might trigger a noise or a wave. Learners will need to think about how they can keep track of this count.

          Support

          Variables may still be a very new concept for learners. The connection to real world examples is crucial. This lesson uses recipes, with the number of cakes being a variable or the amount or temperature of materials in an experiment being variables.

          Reinforce that the purpose of the learning is not to build a complex program with variable but rather just to describe what they are and change the declared variable. Share with learners more examples of variable in their daily life to remove the stigma that 'variables are hard': learners will use and interact with variables on a daily basis without realising or thinking about it.

          Some examples of variables can include:

          • money in a savings account varies as you deposit or withdraw funds, and with interest
          • how much sleep you get on a nigh can vary based upon how full your day is, how exciting your next day will be or other factors
          • amount of homework can vary based on the day of the week, the subject, the teacher, the time of year, and other factors

          Additional Reading


          • Technologies: Craft, Design, Engineering and Graphics
          • Technologies: Computing Science
          • Literacy & English: Listening and Talking
          • Health and Wellbeing: Mental, Emotional, Social and Physical Wellbeing
          • Literacy & English: Writing
          • Computing, Design and Technology: Design and Technology
          • Computing, Design and Technology: Computing
          • CSTA Education Standards
          • Elementary Technology Applications: Grade 3 to Grade 5
          • Digital Technologies, Design & technologies: Design & Technologies
          • Digital Technologies, Design & technologies: Digital Technologies
          • International Society for Technology in Education (ISTE)