Lesson 14: If/Else with Bee
55 minutes
Overview
In this skill-building lesson, your class will continue to code with conditionals, allowing them to write code that functions differently depending on the specific conditions the program encounters.
Purpose
After being introduced to conditionals in "Conditionals with Cards," students will now practice using them in their programs. The "if / else" blocks will allow for a more flexible program. The bee will only collect nectar if there is a flower or make honey if there is a honeycomb.
Standards
AP - Algorithms & Programming
- 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
Agenda
Objectives
Students will be able to:
- Solve puzzles using a combination of looped sequences and conditionals.
- Translate spoken language conditional statements into a program.
Preparation
- Play through the puzzles to find any potential problem areas for your class.
- Make sure every student has a reflection journal.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the students
- Unplugged Blocks (Courses C-F) - Manipulatives
Vocabulary
- Conditionals - Statements that only run under certain conditions.
Teaching Guide
Warm Up (10 minutes)
Introduction
Review the "Conditionals with Cards" activity with your students.
- What is a conditional statement?
- When is a conditional useful?
- What are some of the conditions you used in the last activity?
Now we're going to use conditionals with the Code.org bee to help him deal with some mysterious clouds. We don't know if his flowers have nectar or not, so we'll need to use conditionals to make sure that we collect nectar if it's there, but that we don't try to collect nectar from a flower that doesn't have any.
Preview of Online Puzzles
Pull up a puzzle from this lesson, we recommend puzzle 9.
- Ask the class what the bee should do when it gets to the cloud.
- The bee should use a conditional to check for a flower or a honeycomb.
- Use the "if at flower / else block". Ask the class what the bee should do if there's a flower. If there's not a flower, there will be a honeycomb. What should the bee do then?
- The bee should "get nectar" if there is a flower and "make honey" if there is a honeycomb.
Fill in the rest of the code and press "Run". Discuss with the class why this worked.
Main Activity (30 minutes)
If/Else with Bee
These puzzles might sprout some questions, so have the students work in pairs or implement the "Ask three before you ask me" rule (have the students ask three other peers for help before they go to the teacher.) This will spark discussions that will develop each student's understanding.
Wrap Up (15 minutes)
Reflection
Prompts:
- What was today's lesson about?
- How did today's lesson make you feel?
- What conditionals did you use in your code today?
- What are some other conditionals a bee might use? Examples include:
- if there is a tree in front of me, buzz out of the way
- if my wing is hurt, rest on the ground
- if I see another bee, say "Hello!"
Extended Learning
Use these activities to enhance student learning. They can be used as outside of class activities or other enrichment.
True/False Tag
- Line students up as if to play Red Light / Green Light.
- Select one person to stand in front as the Caller.
- The Caller chooses a condition and asks everyone who meets that condition to take a step forward.
- If you have a red belt, step forward.
- If you are wearing sandals, take a step forward.
- Try switching it up by saying things like "If you are not blonde, step forward."
Nesting
- Break students up into pairs or small groups.
- Have them write if statements for playing cards on strips of paper, such as:
- If the suit is clubs
- If the color is red
- Have students create similar strips for outcomes.
- Add one point
- Subtract one point
- Once that's done, have students choose three of each type of strip and three playing cards, paying attention to the order selected.
- Using three pieces of paper, have students write three different programs using only the sets of strips that they selected, in any order.
- Encourage students to put some if statements inside other if statements.
- Now, students should run through all three programs using the cards that they drew, in the same order for each program.
- Did any two programs return the same answer?
- Did any return something different?
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.