0% found this document useful (0 votes)
4 views

Educator guide - Unit 3 Variables

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Educator guide - Unit 3 Variables

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Introduction to Computer

Science

Unit 3:
Variables

Educator guide
makecode.microbit.org
Table of Contents
Overview....................................................................................................................................................... 3
Unit summary............................................................................................................................................. 3
Lessons....................................................................................................................................................... 3
Learning goals............................................................................................................................................ 3
CSTA K-12 computer science standards..................................................................................................... 4
Required educator preparation...................................................................................................................... 5
Preparing to lead the unit........................................................................................................................... 5
Required skills............................................................................................................................................ 5
Recommended resources........................................................................................................................... 5
Lesson A: Understanding variables................................................................................................................ 6
Lesson plan................................................................................................................................................ 6
Outline........................................................................................................................................................ 6
Before the lesson........................................................................................................................................ 6
Lesson details............................................................................................................................................. 7
Section 1: Introduction to variables......................................................................................................... 7
Section 2: Understanding the variable system........................................................................................8
Section 3: Wrap-up................................................................................................................................ 10
After the lesson........................................................................................................................................ 10
Lesson A assessments.............................................................................................................................. 10
Lesson B: Make a game scorekeeper........................................................................................................... 12
Lesson plan.............................................................................................................................................. 12
Outline...................................................................................................................................................... 12
Before the lesson...................................................................................................................................... 12
Lesson details........................................................................................................................................... 13
Section 1: Introduction.......................................................................................................................... 13
Section 2: Code with variables.............................................................................................................. 13
Section 3: Wrap-up................................................................................................................................ 24
After the lesson........................................................................................................................................ 24
Lesson B assessments.............................................................................................................................. 25
Lesson C: Everything counts........................................................................................................................ 27
Lesson plan.............................................................................................................................................. 27
Outline...................................................................................................................................................... 27
Before the lesson...................................................................................................................................... 27
Lesson details........................................................................................................................................ 27
Section 1: Introduce the lesson............................................................................................................. 27
Section 2: Make a micro:bit project using variables..............................................................................27
Section 3: Wrap-up................................................................................................................................ 32
After the lesson........................................................................................................................................ 33
Lesson C assessments.............................................................................................................................. 33

Overview
Unit summary
Introduction to Computer Science Unit 8: Booleans | 2
This unit introduces the use of variables to store
information. Students will practice giving variables
unique and meaningful names, and use basic
mathematical operations for adding, subtracting,
multiplying, and dividing variable values. In the
unplugged activity, students learn to differentiate
between constants and variables by tracking score as Once-a-week timeframe
they play a simple game of Rock Paper Scissors. Then
they code a program for their micro:bit that keeps and If your class meets only once a week,
displays the score of the game by using the this unit may take four weeks to
programmable buttons for input and the LED screen for complete.
output. In the final project, students code their own
unique program using variables, and design and build an Week 1: Lesson A: Variables in daily
object that uses the micro:bit to track score, count steps, life
turns, or something else.
Week 2: Lesson B: Make a game
scorekeeper (only up to Adding On
Lessons with Mathematical Operations)

Each of the following lessons is intended to be broken Weeks 3–4: Lesson C: Everything
into as many class sessions as needed to complete the counts (approx. 60-120 min)
activities.

Lesson A: Variables in daily life (approx. 45-60 min)


Lesson B: Make a game scorekeeper (approx. 60-75 min)
Lesson C: Everything counts (approx. 60-120 min)

Learning goals
During this unit, students 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
variable values.
 Apply the above knowledge and skills to create a unique program that uses variables as an integral
part of the project.

CSTA K-12 computer science standards


Targeted standards for this unit:

1B-AP-09 Create programs that use variables to store and modify data.
2-AP-11 Create clearly named variables that represent different data types and perform operations on
their values.

Introduction to Computer Science Unit 8: Booleans | 3


Required educator preparation
Preparing to lead the unit
The following tasks are relevant to all lessons in the unit. For lesson-specific preparation tasks and any
additional materials, see the “Before the lesson” section of each lesson.

 Watch the correlating unit quick-start video for a brief, high level introduction to the activities and
project.
 Review all materials thoroughly and become confident with content.
 Practice all activities and check your programming against the solution link provided with the
coding activities.

Required skills
To lead the activities in this unit successfully, you need to be able to:

 Explain the difference between constants and variables, and the following types of variables:
 Number
 String
 Boolean
 Sprite
 Array
 Use the following new blocks in Microsoft MakeCode:
 ‘make a variable’ button, ‘set variable to (0)’, and ‘change variable by (1)’ blocks from the
Variables Toolbox.
 ‘show string’, ‘show number’, and ‘pause (ms)’ blocks from the Basic Toolbox.
 Addition blocks from the Math Toolbox.

Recommended resources
If you would like additional support to master the concepts and skills covered in this unit, review the
following resources.

 Learn more about Variables blocks at makecode.microbit.org/blocks/variables


 Learn more about the Basic blocks at makecode.microbit.org/reference/basic
 Learn more about Input blocks at makecode.microbit.org/reference/input
 Learn more about Math blocks at makecode.microbit.org/blocks/math
 Review micro:bit safety advice at microbit.org/guide/safety-advice
 Search the micro:bit support knowledge base at support.microbit.org/support/home

Introduction to Computer Science Unit 3: Variables | 4


Lesson A: Understanding variables
Lesson plan
1. Introduce the concept of variables.
2. Lead the “Keeping score” unplugged activity.

Outline
Section 1: Introduction to variables

 Overview: Introduce the learning goals and concept of variables


Section 2: Understanding variables

 Unplugged activity: Keeping score


Section 3: Wrap-up

 Review: Review learning goals, what the students accomplished, and preview the next lesson
 Exit ticket: Distribute and collect the exit ticket to assess learning

Before the lesson


 Decide how you’ll pair (or trio up) students in the unplugged activity or whether you’ll let students
self-select.
 Print one exit ticket per student (printable versions are found in the assessment guide).

Introduction to Computer Science Unit 3: Variables | 5


Lesson details

Section 1: Introduction to variables

Educator notes

1. Write the “Do now” on the board for students to think about as they arrive:
What are two physical objects that can hold items inside them?
Answer: Responses will vary, e.g., backpack, wallet, notebook, bookcase, house, car, purse, etc.
2. Introduce the lesson, learning goals, and responses to the “Do now.”
3. Introduce the concept of variables.

Overview: Variables
From our previous lesson, we learned that computer programs process information. Some of the
information that is input, stored, and used in a computer program has a value that is constant, meaning it
does not change throughout the course of the program. An example of a constant in math is “pi” because
“pi” has one value that never changes (it is 3.14). Other pieces of information have values that vary or
change during the running of a program. Programmers create variables to hold the value of information
that may change. In a game program, a variable may be created to hold the player’s current score, since
that value would change (hopefully!) during the course of the game.

Ask the students to think of some pieces of information in their daily life that are constants and others that
are variables.

 What pieces of information have values that don’t change during the course of a single day (i.e., are
constants)?
 What pieces of information have values that do change during the course of a single day (i.e., are
variables)?

Constants and variables can be numbers and/or text.

Examples

In one school day…

 Constants: The day of the week, the year, student’s name, the school’s address, the student’s
birthday
 Variables: The temperature/weather, the current time, the current class, whether they are standing
or sitting…

Variables hold a specific type of information. The micro:bit’s variables can keep track of numbers, strings,
Booleans, sprites, and arrays. The first time you use a variable, its type is assigned to match whatever it is
holding. From that point forward, you can only change the value of that variable to another value of that
same type.

Introduction to Computer Science Unit 3: Variables | 6


 A number variable could hold numerical data such as the year, the temperature, or the degree of
acceleration.
 A string variable holds a string of alphanumeric characters such as a person’s name, a password, or
the day of the week.
 A Boolean variable has only two values: true or false. For example, you might have certain things
that happen only when the variable called GameOver is false.
 A sprite is a special variable that represents a single dot on the screen and holds two separate
values for the row and column the dot is currently in.
 An array is another special type of variable that holds a list of multiple items.

Section 2: Understanding the variable system

Educator notes

1. Follow the instructions to lead the unplugged activity.

What is an “unplugged” activity?

An unplugged activity is an activity that takes place away from the computer—in other words,
“unplugged” from technology. This introduces new concepts in a fun way that gets students up and
moving, often reacting and interacting with other students face to face while playing a game or
completing a challenge. Unplugged activities allow students to practice concepts away from devices
so that when they move to coding activities, they have already walked through and thought about
the concepts on their own.

Introduction to Computer Science Unit 3: Variables | 7


Unplugged activity: Keeping score

Objective

The objective of this activity is to experience creating and working with variables by pairing up and playing
Rock, Paper, Scissors.

Instructions

Ask students to keep track of their scores in their


workbooks.

You can also have students play in groups of three


with the third student acting as the scorekeeper.

Students will keep track of how many times each


player wins as well as the number of times the
players tie.

Play: Have students play Rock, Paper, Scissors for


about a minute. When done, ask the students to add
up their scores and how many rounds they played.

Play again: Tell students they will now start over and
play again for another minute. When done, ask the
students to add up their scores and how many rounds
they played.

Discussion

Ask some students to share how they kept track of player


scores. There may be some variety, but most will have
written down the players’ names with marks near the
names representing the wins of each player. And they
may have made a separate place for recording ties.

Ask the students what parts of the score sheet represent


constants—values that do not change through the course
of a gaming session.

Example: The players’ names are constants.

Ask the students what parts of the score sheet represent


variables, values that do change through the course
of a gaming session.

Example: The players’ number of wins are variables.

Ask the students what types of variables they used in


their gaming session.

Example: The players’ score is a number variable type.

Introduction to Computer Science Unit 3: Variables | 8


Section 3: Wrap-up

Educator notes

1. Review learning goals with students, what they accomplished, and preview the next lesson.
2. Distribute and collect the exit ticket.

After the lesson

Assessment
 Review the exit ticket responses.

Reflection
 Consider if there were any concepts of the lesson or exit ticket students struggled with that you
might want to reinforce or re-teach at the beginning of the next lesson.
 Consider what aspects of the lesson students found engaging and how you might emphasize those
in the next lesson.
 Follow up on any questions that arose during the lesson that require additional research on your
part.

Lesson A assessments

“Do now”

Format: Written on the board at the start of the lesson.

 What are two physical objects that can hold items inside them?
Answer: Responses will vary, e.g., backpack, wallet, notebook, bookcase, house, car, purse, etc.

Introduction to Computer Science Unit 3: Variables | 9


Exit ticket

Format: Printed half-page handout for students to complete and turn in as they leave class. (Printer-
friendly versions are found in the assessment guide.)

Questions Answers

1. What’s the difference between a Responses similar to the following:


constant and a variable?
 The value of a constant doesn’t change
 The value of a variable can change

2. What are two types of variables we


Responses can be any two of the following:
learned about today?

 Number
 String
 Boolean
 Sprite
 Array

Introduction to Computer Science Unit 3: Variables | 10


Lesson B: Make a game scorekeeper
Lesson plan
1. Lead the “Scorekeeper” activity.
2. Assess learning with the unit quiz.

Outline
Section 1: Introduction

 Overview: Introduce the learning goals


Section 2: Code with variables

 Coding activity: Scorekeeper


 Knowledge check: Unit quiz
Section 3: Wrap-up

 Review: Review learning goals, what the students accomplished, and preview the next lesson

Before the lesson


 Print one quiz per student (see the assessment guide for a printable format).
 Ensure you have the needed hardware for each student (or pair):
▪ Computer, laptop, or tablet
▪ Micro:bit
▪ Micro-USB cable
▪ Battery pack (with two AAA batteries)

Introduction to Computer Science Unit 3: Variables | 11


Lesson details

Section 1: Introduction

Educator notes

1. Write the “Do now” on the board for students to think about as they arrive:
In programming, what’s a variable?
Answer: A variable holds the value of information that may change when the program is running.
2. Introduce the lesson, learning goals, and coding activities.
3. Discuss their responses to the “Do now.”

Section 2: Code with variables

Educator notes

1. Use our established equipment safety procedures for distributing and using the hardware, and
ensure students are properly set up to begin coding in MakeCode and micro:bit.
2. Follow the instructions to lead the birdhouse activity. Do the activity on your device connected to
the projector or presentation screen and have students follow along as you complete each step. If
you don’t have a projector or screen, move throughout the room between steps to check for
understanding and help facilitate the activity.
3. Pause after each step to check for understanding and take questions, as needed.
4. If your program doesn’t execute properly, ask your students for help to debug and use the
solution link as needed.
5. After the activity, distribute the quiz (see the assessment guide for a printable format).
6. If you have time during class, consider reviewing the quiz answers as a group activity.

What is a “birdhouse” activity?

Each unit contains a micro:bit activity, which we informally refer to as a “birdhouse” activity, after
the innumerable wooden birdhouses so many of us made in wood shop as a way to master basic
skills. The activity is an example that walks students step by step through building a project that
demonstrates that lesson’s topic. By the time students finish the activity, they will have written code
that they can use in a different project of their own design.

Introduction to Computer Science Unit 3: Variables | 12


Tips

Some students will finish the activity more quickly than others. Those students can then be a helpful
resource for their classmates, or they can challenge themselves by modifying, or “modding”, the
activity to do something different. We have provided examples and suggestions at the end of many
of these activities; feel free to suggest your own (or encourage your students to come up with their
own ideas!)

Coding activity: Scorekeeper


This micro:bit activity guides the students to create a program with three variables that will keep score for
their Rock, Paper, Scissors game.

Overview

Tell the students that they will be creating a program that will act as a scorekeeper for their next Rock,
Paper, Scissors game. They will need to create variables for the parts of scorekeeping that change over the
course of a gaming session.

What are those variables?

 The number of times the first player wins


 The number of times the second player wins
 The number of times the players tie

Creating and naming variables

Lead the students to create meaningful names for their variables.

 What would be a unique and clear name for the variable that will keep track of the number of times
Player A wins?
 Student suggestions may include PAW, PlayerA, AButtonPress, AButtonCount, PlayerAWins…
 Discuss why (or why not) different suggestions make clear what value the variable will hold. In
general, variable names should clearly describe what type of information they hold.

Introduction to Computer Science Unit 3: Variables | 13


1. In MakeCode, start a new project and name it something like: Scorekeeper. From the Variables menu,
make and name these three variables: PlayerAWins, PlayerBWins, PlayersTie.

Initializing the variable value


2. It is important to give your variables an initial value. The initial value is the value the variable will hold
each time the program starts. For our counter program, we will give each variable the value 0 (zero) at
the start of the program.

Updating the variable value

In our program, we want to keep track of the number of times each player wins and the number of times
they tie. We can use the buttons A and B on the micro:bit to do this.

Introduction to Computer Science Unit 3: Variables | 14


The pseudocode, written in words, is:

 Press button A to record a win for Player A


 Press button B to record a win for Player B
 Press both button A and button B together to record a tie
We already initialized these variables and now need to code to update the values at each round of the
game.

 Each time the scorekeeper presses button A to record a win for Player A, we want to add one to the
current value of the variable PlayerAWins.
 Each time the scorekeeper presses button B, to record a win for Player B, we want to add one to the
current value of the variable PlayerBWins.
 Each time the scorekeeper presses both button A and button B at the same time to record a tie, we
want to add one to the current value of the variable PlayersTie.

3. From the Input menu, drag three of the ‘on button A pressed’ blocks to your Workspace. Leave one
block with ‘A’. Use the dropdown menu in the block to choose ‘B’ for the second block and ‘A+B’ for the
third block.

4. From the Variables menu, drag three of the ‘change variable by 1’ blocks to the coding Workspace.

Introduction to Computer Science Unit 3: Variables | 15


5. Place one ‘change (variable)’ block into each of the ‘on button pressed’ blocks.
6. Choose the appropriate variable from the pull-down menus in the ‘change by 1’ blocks.

Adding user feedback

Whenever the scorekeeper presses button A, button B, or both buttons together, we will give the user
visual feedback acknowledging that the user pressed a button. We can do this by coding our program to
display:

 An ‘A’ each time the user presses button A to record a win for Player A
 A ‘B’ for each time the user presses button ‘B’ to record a win for Player B
 A ‘T’ for each time the user presses both button A and button B together to record a tie
7. We can display an ‘A’, ‘B’, or ‘T’ using either the ‘show leds’ block or the ‘show string’ block.

Introduction to Computer Science Unit 3: Variables | 16


Introduction to Computer Science Unit 3: Variables | 17
In this example, we have used the ‘show leds’ block.

Notice that we added a ‘clear screen’ block after showing ‘A’, ‘B’, or ‘T’. What do you think would happen if
we did not clear the screen? Try it.

Showing the final values of the variables

To finish our program, we can add code that tells the micro:bit to display the final values of our variables.
Since we have already used buttons A and B, we can use the ‘on shake’ event handler block to trigger this
event. We can use the ‘show string’, ‘show leds’, ‘pause’, and ‘show number’ blocks to display these final
values in a clear way.

8. From the Input Toolbox drawer, drag an ‘on shake’ block to the coding Workspace. Then, from the
Basic Toolbox drawer, drag a ‘show string’ block inside it.

Change the text of the string from “Hello!” to: “Wins:“

9. From the Basic Toolbox, drag a ‘show leds’, a ‘show number’, and a ‘pause’ block to the coding
Workspace and connect them under the ‘show string’ block. Select the boxes in the ‘show leds’ block
to make the letter A.

Introduction to Computer Science Unit 3: Variables | 18


10. When we shake the micro:bit, we want it to display, Wins: , then display the letter A followed by the
number of wins for Player A.
a. From the Variables Toolbox, drag the ‘PlayerAWins’ variable to replace the 0 in the ‘show
number’ block.
b. To add an adequate pause before showing the number of wins for Player B, use the drop-down
menu in the ‘pause’ block and select 1 sec (which is 1000 ms).

Introduction to Computer Science Unit 3: Variables | 19


11. Now, we can follow the same steps to show the number of wins for Player B.
a. From the Basic Toolbox, drag the ‘show leds’, ‘show number’, and ‘pause’ blocks to the coding
Workspace and add them under the ‘pause (ms) 1000’ block.
b. Select the boxes in the ‘show leds’ block to display the letter B.
c. From the Variables Toolbox, drag the ‘PlayerBWins’ variable to replace the 0 in the ‘show
number’ block.
d. In the ‘pause’ block, use the dropdown menu and select 1 second.

12. To show the number of ties, go to the Basic Toolbox, and drag the ‘show string’, ‘show number’, and
‘pause’ blocks underneath the last ‘pause (ms) 1000’ block and still inside the ‘on shake’ block.

13. In the ‘show string’ block, change the “Hello!” to “Ties: “. Then, from the Variables Toolbox, drag the
‘PlayersTie’ variable block to replace the 0 in the ‘show number’ block. And change the ‘pause’ block to
1 second.

Introduction to Computer Science Unit 3: Variables | 20


14. There is one last block to add. Can you guess what it is? From the Basic Toolbox, drag a ‘clear screen’
block underneath the final ‘pause’ block.

Introduction to Computer Science Unit 3: Variables | 21


Complete program

Solution link: makecode.microbit.org/_MepbrefDmija

Try it out!

Download the Scorekeeper program to the micro:bit, and have the students play one last round of Rock,
Paper, Scissors using their micro:bits to act as the Scorekeeper.

Adding on with mathematical operations

There is more we can do with the input we received using this program. We can use mathematical
operations on our variables.

Example: Perhaps you’d like to keep track of and show the player the total number of rounds that were
played. To do this, we can add the values stored in the variables we created to keep track of how many
times each player won and how many times they tied.

Introduction to Computer Science Unit 3: Variables | 22


15. In order to do this, we can add the code to our program under the ‘on shake’ event handler.
a. First, display a string to show the player that the following sum represents the total number of
rounds played.
b. Our program will add the values stored in the variables PlayerAWins, PlayerBWins, and
PlayersTie and then display the sum of this mathematical operation.
c. The blocks for the mathematical operations adding, subtracting, multiplying, and dividing are
listed in the Math section of the Toolbox.

Even though there are four blocks shown for these four operations, you can access any of the four
operations from any of the four blocks, and you can also access the exponent operation from these blocks.

16. Replace the default values of 0 with the names of the variables we want to add together. Notice that
because we are adding three variables together, we need a second math block. First, we add the
values for PlayerAWins and PlayerBWins, then add PlayersTie.

Save, download, and try the program again to make sure that it runs correctly and displays the correct
numbers for each variable.

Introduction to Computer Science Unit 3: Variables | 23


Discussion

Remember: The micro:bit is a device that processes input and displays it as output in some way. By
storing values in variables, you can perform mathematical operations on that data that provides useful
information.

What other math operations could provide valuable information from the values stored in these variables?

Examples:

 Calculate and display a player’s wins and/or losses as a percentage of all rounds played.
 Calculate and display the number of tied games as a percentage of all rounds played.
How would you code those math operations?

If time permits: Have students code one or more of their ideas or do one as a group activity.

Activity: Unit Quiz


Distribute the quiz (printable versions are found in the assessment guide). If you have time during class,
consider reviewing the quiz answers as a group activity.

Section 3: Wrap-up

Educator notes

1. Review the learning goals with students, what they accomplished, and preview the next lesson.
2. Use your established equipment safety procedures for collecting and storing the hardware.

After the lesson


Assessment
 Review and grade the quiz (unless you reviewed with your students in class).

Reflection
 Consider if there were any concepts of the lesson or quiz students struggled with that you might
want to reinforce or re-teach at the beginning of the next lesson.
 Consider what aspects of the lesson students found engaging and how you might emphasize those
in the next lesson.
 Follow up on any questions that arose during the lesson that require additional research on your
part.

Introduction to Computer Science Unit 3: Variables | 24


Lesson B assessments

“Do now”

Format: Written on the board at the start of the lesson.

 In programming, what’s a variable?


Answer: A variable holds the value of information that may change when the program is running

Quiz

Format: Printed full-page handout for students to complete during class. (Please see the assessment guide
for printer-friendly versions to distribute to students.)

Questions Answers

1. What’s the difference between a constant and a A constant has a value that doesn’t
variable? change. A variable has a value that
may change.

2. Name two variables that can affect how you dress to go Responses will vary, e.g., the
outside. weather/temperature, what’s clean,
holiday season, time of day, formality
of an event, etc.

3. What’s an example of each of the following types of a. Numerical data, e.g., the year,
variables? the temperature, or the degree of
acceleration
a. Number
b. A string of alphanumeric
b. String
characters, e.g., a person’s name,
c. Boolean a password, or the day of the
week
c. Only two values: true or false
(can also be represented by
0=false, 1=true)

4. Why is it important to name variables in a clear and Variable names should clearly
meaningful way? describe what type of information
they hold so they are easily
recognizable in the program and you
can find problems or bugs easier.

5. True or false: You can only use the default variable False. You can make a variable with
names provided in the Variables toolbox drawer. any name you want/need for a
program with the Make a Variable
button.

6. Write the pseudocode in words to describe what these Something similar to:
coding blocks do:
At the start of the program, the
variables for Player A wins, Player B
wins, and player ties are all set to
zero.

Introduction to Computer Science Unit 3: Variables | 25


7. Write the pseudocode in words to describe what these Something similar to:
coding blocks do:
When you shake the micro:bit, the
lights will display “Total rounds
played:” and the number value that
totals the number of wins for player A
plus the number of wins for Player B
plus the number of ties.

Introduction to Computer Science Unit 3: Variables | 26


Lesson C: Everything counts
Lesson plan
1. Introduce and facilitate the project.

Outline
Section 1: Introduce the lesson

 Overview: Introduce the learning goals


Section 2: Make a micro:bit project using variables

 Coding project: Everything counts


Section 3: Wrap-up

 Exit ticket: Students complete a Reflection Diary entry for their project
 Review: Review the learning goals, what students accomplished, and preview the next unit

Before the lesson


 If you will be reviewing the lesson B quiz, prepare to address any themes the students are
struggling with.
 Email the Reflection Diary questions for the project to students or post it in a shared drive, so
students can send their responses to you electronically.
 Although the student workbooks have space for note-taking and drawing, consider having extra
paper available, in case any students need more designing space.
 Ensure you have the needed hardware for each student (or pair):
 Computer, laptop, or tablet
 micro:bit
 Micro-USB cable
 Battery pack (with two AAA batteries)
 Ensure the arts and crafts supplies are restocked, e.g.:
 Pizza boxes/scrap cardboard  String
 Colored construction paper  Colored markers/pencils
 Colored duct tape  Glue
 Scissors  Tape
 Pipe cleaners  Foil and copper tape
 Feathers, beads, etc.

Introduction to Computer Science Unit 3: Variables | 27


Lesson details

Section 1: Introduce the lesson

Educator notes

1. Write the “Do now” on the board for students to think about as they arrive:
What’s a physical object that counts, holds, or tracks values that you might prototype?
Answer: Responses will vary, e.g., wallet, scorecard, fitness tracker, calculator, etc.
2. Introduce the lesson, learning goals, and discuss responses to the “Do Now.”
3. Review any themes that students are struggling with from the quiz results unless you covered
this at the end of the last lesson.

Section 2: Make a micro:bit project using variables

Educator notes

1. Use your established equipment safety procedures for distributing and using the hardware and
ensure students are properly set up to begin coding in MakeCode and micro:bit.
2. Follow the instructions to explain the expectations for the binary cash register project, the
example, and the scoring rubric, which is also in the student workbook.
3. Encourage students who finish early or need an extra challenge to try one or more of the mod
ideas and/or offer the optional additional binary wristwatch project.
4. After the activity, consider having students share their projects in pairs, small groups, or with the
rest of the class as time allows.
5. Be sure to allow enough time for students to complete their Reflection Diary entry in the next
section.

Objective of projects

Open-ended projects are opportunities to apply the concepts and skills students have developed in
an original and creative way. Students will work on their projects in a “collaboratively independent”
way, which means each student is responsible for turning in his or her own project but is encouraged
to work together and help their peers while doing so. Some form of reflection is an important part of
documenting the learning that has taken place.

Introduction to Computer Science Unit 3: Variables | 28


Activity: Everything counts project
This is an assignment for students to come up with a micro:bit program that counts something. Their
program should keep track of input by storing values in variables and provide output in some visual and
useful way. Students should also perform mathematical operations on the variables to give useful output.

Example: Homemade top with micro:bit revolution counter

Input

Remind the students of all the different inputs available to them through the micro:bit:

 Acceleration  On button pressed

 Light level  On logo down

 Button is pressed  On logo up

 Compass heading  One pin pressed

 Temperature  On screen down

 Running time  On screen up

 On shake  Pin is pressed

Introduction to Computer Science Unit 3: Variables | 29


Project ideas

These examples are in the unit presentation and student workbooks.

1. Duct tape wallet


You can see the instructions for creating a durable,
fashionable wallet or purse out of duct tape: Duct tape
wallet. Create a place for the micro:bit to fit securely. The
starter code at the above link just displays an animation.
For this project, modify the provided starter code to use
Button A to add dollars to the wallet and Button B to
subtract dollars from the wallet.

Extra mod: Use other inputs to handle cents and provide a


way to display how much money is in the wallet in dollars
and cents.

2. Umpire’s baseball counter (pitches and strikes)


In baseball during an at-bat, umpires must keep track of
how many pitches have been thrown to each batter. Use
Button A to record the number of balls (up to four) and the
number of strikes (up to three).

Extra mod: Create a way to reset both variables to zero,


create a way to see the number of balls and strikes on the
screen at the same time.

3. Shake counter
Using the ‘on shake’ block, you can detect when the micro:bit has been shaken and increment a
variable accordingly. Try attaching the micro:bit to a lacrosse stick and keep track of how many times
you have successfully thrown the ball up in the air and caught it.

Extra mod: Have the micro:bit make a sound of increasing pitch every time you successfully catch the
ball.

4. Pedometer
See if you can count your steps while running or doing other physical activities carrying the micro:bit.
Where is it best mounted?

Extra Mod: Design a wearable band or holder that can carry the micro:bit securely so it doesn’t slip out
during exercise.

5. Calculator
Create an adding machine. Use Button A to increment the first number, and Button B to increment the
second number. Then, use Shake or Buttons A + B to add the two numbers and display their sum.

Extra mod: Find a way to select and perform other math operations.

Introduction to Computer Science Unit 3: Variables | 30


Reminders about design thinking

Understand the problem

In any design project, it’s important to start by understanding the problem. You can begin this activity by
interviewing people around you who might have encountered the problem you are trying to solve. For
example, if you are designing a wallet, ask your friends how they store their money, credit cards,
identification, etc. What are some challenges with their current system? What do they like about it? What
else do they use their wallets for?

If you are designing something else, think about how you might find out more information about your
problem through interviewing or observing people using current solutions.

Prototype

Then, start brainstorming. Sketch out a variety of different ideas. Remember that it’s okay if the ideas
seem far-out or impractical. Some of the best products come out of seemingly crazy ideas that can
ultimately be worked into the design of something useful. What kind of holder can you design to hold the
micro:bit securely? How will it be used in the real world, as part of a physical design?

Code the program

Use the simulator to do your programming and test out a number of different ideas. What is the easiest
way to keep track of data? If you are designing for the accelerometer, try to see what different values are
generated through different actions (you can display the value the accelerometer is currently reading
using the ‘show number’ block; clear the screen afterward so you can see the reading).

Introduction to Computer Science Unit 3: Variables | 31


Project expectations

Follow the design thinking approach and make sure your project meets these specifications:

 Uses at least three different variables in a way that’s integral to the program
 Uses unique variable names that clearly describe what information values the variables hold
 Uses mathematical operations to add, subtract, multiply, and/or divide at least two variables
 The program compiles and runs as intended and includes meaningful comments in code
 Provide the written Reflection Diary entry (which we’ll talk about after you complete your project)

Project scoring rubric

Assessment
1 2 3 4
elements

Variables No variables are At least one At least two At least three


implemented. variable is variables are different variables
implemented in a implemented in a are implemented
meaningful way. meaningful way. in a meaningful
way.

Variable names None of the A minority of The majority of All variable names
variable names variable names variable names are unique and
clearly describe are unique and are unique and clearly describe
what information clearly describe clearly describe what information
values the what information what information values the
variables hold. values the values the variables hold.
variables hold. variables hold.

Mathematical No mathematical Uses a Uses a Uses a


operations operations are mathematical mathematical mathematical
used. operation operation on at operation on at
incorrectly or not least one variable least two variables
in a way that is in a way that is in a way that is
integral to the integral to the integral to the
program. program. program.

micro:bit program micro:bit program micro:bit program micro:bit program micro:bit program:
lacks three or lacks two of the lacks one of the
more of the required elements. required elements.  Uses variables
required elements. in a way that is
integral to the
program
 Uses
mathematical
operations to
add, subtract,
multiply, and/or
divide variables
 Compiles and
runs as
intended
 Uses
meaningful

Introduction to Computer Science Unit 3: Variables | 32


comments in
code

Section 3: Wrap-up

Educator notes

1. Explain the expectations and scoring rubric for the Reflection Diary entry for their project, which
is also in the student workbook.
2. Review the learning goals with students, what they accomplished, and preview the next unit.
3. Use your established equipment safety procedures for collecting and storing the hardware.

Reflection Diary
Expectations

Write a reflection of about 150–300 words addressing the following points:

 What was the problem you were trying to solve with this project?
 What were the variables that you used to keep track of information?
 What mathematical operations did you perform on your variables? What information did you
provide?
 Describe what the physical component of your micro:bit project was (e.g., an armband, a wallet, a
holder, etc.)
 How well did your prototype work? What were you happy with? What would you change?
 What was something that was surprising to you about the process of creating this project?
 Describe a difficult point in the process of designing this project and explain how you resolved it.
 Publish your MakeCode program and include the link.

Diary entry scoring rubric

Assessment
1 2 3 4
elements

Diary entry Diary entry is Diary entry is Diary entry is Diary entry
missing three or missing two of the missing one of the addresses all
more of the required elements. required elements. elements.
required elements.

Introduction to Computer Science Unit 3: Variables | 33


After the lesson

Assessment
 Review and grade the projects and diary entries. (A full page, printer-friendly version of the project
and diary entry scoring rubric is available in the assessment guide.)

Reflection
 Consider if there were any concepts of the lesson, project, or diary entries students struggled with
that you might want to reinforce or re-teach before or at the beginning of the next unit.
 Consider what aspects of the lesson students found engaging and how you might emphasize those
in the next unit.
 Follow up on any questions that arose during the lesson that require additional research on your
part.

Lesson C assessments

“Do now”

Format: Written on the board at the start of the lesson:

 What’s a physical object that counts, holds, or tracks values that you might prototype?
Answer: Responses will vary, e.g., wallet, scorecard, fitness tracker, calculator, etc.

Reflection Diary questions

Format: Provide to students electronically. Copy and paste from below.

Unit 3 Variables: Reflection Diary

Write a diary entry of about 150–300 words addressing the following points:

 What was the problem you were trying to solve with this project?
 What were the variables that you used to keep track of information?
 What mathematical operations did you perform on your variables? What information did you
provide?
 Describe what the physical component of your micro:bit project was (e.g., an armband, a wallet, a
holder, etc.)
 How well did your prototype work? What were you happy with? What would you change?
 What was something that was surprising to you about the process of creating this project?
 Describe a difficult point in the process of designing this project and explain how you resolved it.
 Publish your MakeCode program and include the link.

Introduction to Computer Science Unit 3: Variables | 34

You might also like