< Course D (2022)

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.

CSTA K-12 Computer Science Standards (2017)
    • 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.

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the teachers
For the students

Vocabulary

  • Conditionals - Statements that only run under certain conditions.

Teaching Guide

Warm Up (10 minutes)

Introduction

Display: Show “Reflect” slide

Review the "Conditionals with Cards" activity with your students.

  • What is a conditional statement?
  • When is it useful for you to use a conditional in your program?

Preview of Online Puzzles

Display: Show “Preview - If/Else with Bee” slide

Say: 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.

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.

Vocabulary

Display: Show “Vocabulary” slide

Conditionals - Statements that only run under certain conditions.

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.

Display: Show “Conditionals: If Statements” video

Display: Show “Level 2 - Prediction” slide

Display: Show “If and If/Else Statements” video

Display: Show “Level 9 - Skill Building” slide

Display: Show “Level 10 - Predict” slide

Display: Show “Level 11 - Challenge” slide

Display: Show “Level 12-13 - Practice” slide

Display: Show “Level 14-15 - Challenge” slide

Lesson Extras

Display: Show “Lesson Extras slide

Wrap Up (15 minutes)

Reflection

Display: Show “Reflect” slide

Reflect: What conditionals did you use in your code today?

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?
Creative Commons License (CC BY-NC-SA 4.0).

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.