# Lesson 9: Changing Variables with Bee

## Overview

This lesson will help illustrate how variables can make programs more powerful by allowing values to change while the code is running.

## Purpose

You don't always know what a value is going to be before you begin your program. Sometimes, values change while your code is running. This lesson will illustrate how code with changing values can be helpful.

## Objectives

### Students will be able to:

• Identify areas where they can use variables to modify quantities during runtime.
• Examine code to find places where variables can be substituted for specific values.

## Preparation

• Play through the puzzles to find any potential problem areas for your class.
• Make sure every student has a journal.

## Vocabulary

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

# Teaching Guide

## Warm Up (15 min)

### Introduction

This series is a little different than what students have done in the past. Now, instead of simply assigning a value to a variable and running your code, you'll need to help students see how a variable can be modified during program runtime.

Display Show students the play area from one of the later puzzles.

There are several things to unpack here, so you might need to give your students a chance to look at it critically before you expect them to do anything with it.

Think/Pair: Suppose all of the flowers/honeycomb in this picture had the same amount of nectar/honey. How would you solve this puzzle?

Share: Let students share their ideas until you decide on one that the entire class is good with.

Discuss: Now, imagine that we didn't want to have to write a separate chunk of code for each set of flowers and honeycomb. How could we use a variable to have our loop do this for us?

(Eventually, you'll want to get to the place where you initialize a variable to the original value, then change it each time through the loop so that it's ready for the next time.)

## Main Activity (30 min)

### Online Puzzles

This set of puzzles takes some serious computational thinking skills. If you find that students are getting stuck, help them break down the puzzles into the individual pieces:

• What would it look like if the flowers/honeycomb all had the same amount of nectar/honey?
• What would it look like without the functions?
• Now how can you use a variable to get the quantities the way you want them?
• Now can you build it back up to use a function?

Hint: Puzzle 7 becomes much easier if students utilize the `while path ahead` loop instead of a variable.

## Wrap Up (15 min)

### 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 did you feel during today’s lesson?
• What are some ways you have used variables so far?
• What else do you think you can do with variables?
View on Code Studio

### Student Instructions

View on Code Studio

### Student Instructions

View on Code Studio

### Student Instructions

"Such an a-MAZE-ing garden!"

In this puzzle, each patch needs the variable to be one less than the patch before. Subtract one from the variable each time through the loop if you want to use the same function to solve this level.

View on Code Studio

### Student Instructions

"Let's keep going!"

Edit the code to make it work for this puzzle.

View on Code Studio

### Student Instructions

• Challenge
• 6
• (click tabs to see student view)
View on Code Studio

### Student Instructions

• Practice
• 7
• (click tabs to see student view)
View on Code Studio

## Standards Alignment

#### CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
• 1B-AP-09 - Create programs that use variables to store and modify data.
• 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.