Variables

Variable value

This unit introduces the use of variables to store information. You will practice giving variables unique and meaningful names, and use basic mathematical operations for adding, subtracting, multiplying, and dividing variable values. You’ll code a program for the micro:bit that keeps and displays the score of a game of Rock, Paper Scissors by using the programmable buttons for input and the LED screen for output. In the final project, you’ll code your own unique program using variables, and design and build an object that uses the micro:bit to track score, count steps, turns, or something else.

Lesson Objectives

You will…

  • Understand what variables are and why and when to use them in a program.
  • Learn how to create a variable, set the variable to an initial value, and change the value of the variable within a micro:bit program.
  • Learn how to create meaningful and understandable variable names.
  • Understand that a variable holds one value at a time.
  • Understand that when you update or change the value held by a variable, the new value replaces the previous value.
  • Learn how to use the basic mathematical blocks for adding, subtracting, multiplying, and dividing variables.
  • Apply the above knowledge and skills to create a unique program that uses variables as an integral part of the program.

Lesson plan

  1. Overview: Variables in Daily Life
  2. Activity: Make a Game Scorekeeper
  3. Project: Everything Counts

Targeted CSTA standards