# Lesson 5: Conditionals Explore

## Overview

Students learn the basics of conditionals through an unplugged activity using the sticky notes and plastic baggies from the Variables Explore lesson. Flowcharts are introduced as a way to understand how computers make decisions using Boolean expressions.

## Purpose

The warm up activity is designed to provide context for the Conditionals progression. The subsequent activity provides students a physical mental model they will be able to use when they start programming with conditionals in the subsequent lessons.

## Objectives

### Students will be able to:

• Use appropriate vocabulary to describe Boolean expressions and conditional statements
• Evaluate expressions that include Boolean values, comparison operators, and logical operators
• Trace simple programs that use Boolean expressions and conditional statements

## Preparation

• 3 sandwich baggies per pair of students
• packs of red, yellow, and blue stickies
• pens / pencils
• 1 dry erase marker per four students (pairs can share)
• Review the slides and click through all animations

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

Forum

# Teaching Guide

## Lesson Modifications

Attention, teachers! If you are teaching virtually or in a socially-distanced classroom, please read the full lesson plan below, then click here to access the modifications.

## Warm Up (5 mins)

### Preview Conditionals

Prompt: Imagine you want to make a decision about what to wear to an event. Name two pieces of information you'd want. How would you use them in your decision?

## Activity (30 mins)

### Conditionals

Group: Group students in pairs.

Teaching Tip

Supplies Substitutions: There's no need to use stickie notes if you have other scraps of colored paper. Also consider cutting stickies in 4 to make them go further. If you don't have dry erase markers handy consider using pieces of masking tape on the baggies.

Distribute: Give each pair of students:

• A small stack of red, yellow, and blue sticky notes
• A pen/pencil
• 3 plastic baggies
• A dry erase marker to share with another group

Display: Use the activity slides for this lesson to guide the unplugged activity on Conditionals.

Slides                     Speaker Notes
Say: Today we are going to explore Conditionals.
Say: Previously, we learned that information can be stored as numbers or strings in variables. These are two different types of data. Numbers and strings can be combined together using operators to make expressions. Expressions are evaluated before storing in variables.
Say: Boolean values are another type of data. They can store the values “true” or “false”. Why would we want that information? Booleans are used to make decisions. If something is true, do this. If something is false, do that.

Click for animation

Do This: You only need two blue sticky notes today. Write down “true” on one and “false” on the other.
Say: Let’s look at this expression. Take a guess as to what Boolean value this evaluates to.

Do This: Hold up the sticky note with the correct value.

Click for animation

Say: The expression evaluates to true, because 3 is less than 8.

Click for animation

Say: The less than symbol is a comparison operator. When we see a comparison operator, we need to stop and evaluate for a Boolean value. There are six different comparison operators - you may be familiar with some of them from math class. Notice the double equal signs for "equal to". Here we are distinguishing from a single equal sign that is used to assign value to a variable. We read a single equal sign as “gets the value”. A double equal sign can be read as "equal to”.
Say: Both sides of the relational operator should be reduced to a single value before we can compare. Think of it in terms of sticky notes. You should have only one sticky note on each side.

Do This: What does 3 + 6 equate to?

Click for animation

Say: Right: 9! Now we can compare 9 and 8 using the relational operator: less than.

Do This: Does this evaluate to true or false? Hold up the correct sticky note.

Click for animation

Say: Let’s evaluate these expressions line by line. It may be helpful to use your sticky notes here.

Do This: Reduce each side of the relational operator to one sticky note. Then evaluate for a Boolean value. Compare your answers with a partner.

Click for animation: When the class is finished, click through to view the answers. The third line may be a little tricky. Remind students to evaluate the information in the parenthesis first. In the fourth line, draw attention to the double equal signs and remind the class double equal signs are a signal to compare if both sides are the same.
Say: The expressions that we evaluate can also contain variables. Remember, variables store information. This information can be different data types like numbers, strings, or even Boolean values themselves. For now, we are going to stick with numbers.

Do This: With a partner, reduce both sides of the relational operator. Then evaluate for a Boolean value.

Click for animation: When the class is finished, click through for the answer. Draw attention to the note: any expression that can be evaluated for true or false is known as a Boolean Expression.
Say: At the beginning of class, we talked about how Booleans are used to make decisions. Let’s see that in action. Consider the following question: Can I go to the movies? I’m allowed to if it’s before 8 o’clock. This may seem like a simple decision! But let’s think about this like a computer.

Do This: What information would the computer need to know in order to answer the question. Create a baggie variable to store the information. Give it a name.
Say: This is a flowchart. It’s an organized way to make a decision or come to a conclusion. Creating a flowchart helps us think like a computer. At the top, we are listing the variables that are needed. Your variable might be called time or clock or really anything. It doesn’t matter as long as you use the same name every time you refer to the variable. For this example, I’m naming my variable “time”. Let’s step through the flowchart with an example to see how it works.
Click for animation

Say: It’s 9 o’clock. Can I go to the movies?

Click for animation

Say: First I assign 9 to the variable time, then I move on to the diamond section.

Click for animation

Say: I see a comparison operator, which let’s me know that we need to stop and evaluate the Boolean expression.

Click for animation

Say: First reduce both sides to a single value. Then evaluate for a Boolean value. In this case, The Boolean expression evaluates to false.

Click for animation

Say: Follow the “false” path, and we arrive at the result: “I can’t go to the movies.”

Note: If students are confused, return back to the previous slide and try running some examples together as a class. Students can hold up true or false when evaluating the Boolean expression. Once students get the hang of using a flowchart, continue on to the next slide.
Say: Here’s another decision that needs to be made. I’m not sure if I have won the game I’m playing. I have won it if my score * (times) my lives is greater than 10.

Do This: Direct students to create baggie variables for the information that needs to be stored and write down the Boolean expression on a spare sticky note or scrap paper. Groups then compare their Boolean expressions.
Say: Take a look at the Boolean expression in the decision section of the flowchart. Is this similar to what you and your partner wrote? Are there other ways we could construct this? (score and lives might have different names, score and lives might be in opposite order, you could write it as 10 < score * lives).

Click for animation

Do This: With a partner, try following the flowchart with a few different inputs.
Say: Here's a new decision we need to make.

Do This: With a partner walk through the steps on the screen. Think about what the Boolean expression will look like.
Say: Here's a flowchart for the question we just considered.

Do This: With your partner, step through the flowchart with a few different inputs.

Note: After students have practice on their own, call on one group to give input values for `dogAge` and `myAge` and step through the flowchart as a class.
Say: What happens if my decision requires several steps? I want to adopt a cat, but I have to have both 40 dollars and be over 14 years old.

Note: Emphasize precise language here. The Boolean is checking if I have 40 dollars - that's exactly 40, not one cent more! In the Conditional Practice lesson, students will return to this flowchart and edit it to account for having more than 40 dollars.
Say: Let's get setup for stepping through the decision making process for this question.

Do This: Set up your baggies, and discuss with a partner how the flowchart might be set up.
Say: This flowchart looks a little different from the previous one. There are two stopping points where a Boolean expression is evaluated. Let’s try this out with an example.

Click for animation: Click through, one step at a time with the class. When you get to a decision point, before clicking to the next animation have students evaluate the expression and hold up a blue sticky note.

Say: Notice in question box, I’ve stated that I can adopt the cat if I have 40 dollars AND (emphasize) I am over 14 years old. I am checking two things. Let’s look at a way to simplify that process.
Say: In the previous example, we had two Boolean expressions to evaluate. We can use logical operators to compare the results of those Boolean expressions. The logical operators we will look at are && (AND),
Say: Now we're going to take a look at something called a Truth Table. We are going to change the color of the sticky notes a little bit. Boolean values will still be on blue stickies, but true will be a dark blue, and false a light blue.

Note: there is no need to supply two different colors of blue sticky notes for these slides. Students can follow along.
Say: This is a Truth Table. It demonstrates all the possible combinations of true and false and what they would evaluate to if combined with the logical operator && (AND). The first one seems obvious to us - if something is true and another thing is true, then the whole thing is true!. Read through each row, and consider what is being stated. In rows 2 and 3, if one value is false, the whole thing evaluates to false. This is what happened with the cat example. On the final line, if both values are false, the final evaluation is false.

Click for animation

Say: What's the takeway? In evaluating two Boolean expressions with the AND operator, both must be true in order for the whole expression to evaluate as true.
Say: Now let's consider a Truth Table for OR.

Do This: With a partner, evaluate each row. For example, if the first sticky is True or the second sticky is True what do you think the whole expression will evaluate to: true or false?

Click for animation: Stop line by line and allow time for groups to make their predictions.

Click for animation

Say: For the OR Truth Table, if either sticky note is True the expression evaluates to true.
Say: The ! NOT table is simple because it reverses the value.

Click for animation: As a class quickly state what the opposite values are and click through the animations.
Say: Let’s return to the cat example. How can we write a single expression that accounts for all the information that needs to be checked?

Do This: With a partner, create the expression using logical operators.

Note: It’s ok if students struggle with this activity. After a few minutes, move on to the next slide and reveal the answer. This will help students make the connection.
Click for animation: Click through the animation step by step and follow along as a class. Allow time to predict at decision points. When the truth table (yellow box) appears on the screen, take a moment to remind students what this is and what it demonstrates. If a value is true and another value is true, it evaluates to true. It’s not expected that students will memorize the truth tables, but they should be familiar with how they work.

Note: If you have extra time, try running this flowchart with other inputs. Try changing the conditions and then running the flowchart (i.e. I can adopt the cat if I have 40 dollars OR I am over 14 years old)

Say: Today we used flowcharts to demonstrate how computers make decisions. In the next class, we will investigate how decisions are made in code.
Do This: Give students a few minutes to craft their own flowcharts and test on each other following the instructions on the screen.

Note: Simple flowcharts are fine, or students can build more complex models. Students are ready to move on when the majority of the class has made and tested a flowchart.
Click for animation: Review the key takeaways on the screen with students.

Click for animation: Review the key takeaways with students.

Teaching Tip

Running the Activity: This activity asks students to follow along as a number of core concepts for programming are introduced. The model is typically that a term or concept is introduced and modeled and then afterwards students are encouraged to try it out on their own. Trying it out typically means they are writing information on a sticky note and sharing it with another group before discussing the results with the whole class.

Slides with animations have an icon in the bottom left corner to let you know you need to click to reveal more of the slide's content.

To help you more easily prepare the activity and keep track of your instructions, detailed instructions have been included as speaker notes in the presentation. Here are some tips to help you throughout the presentation.

• There are opportunities throughout the presentation for students to actively engage. At these moments students should be making things with their manipulatives or using them to answer questions. Use these opportunities to check progress.
• There is a fair amount of new vocabulary introduced but it is introduced gradually and with intentional repetition. Make a point of actively modeling the use of new terms.
• The most important goal here is building a mental model. It is ok if students have some open questions that will get resolved over the subsequent conditional lessons.
• Both you and students can use the "Key Takeaways" to check your understanding at the end.

## Wrap Up (10 mins)

Video: CS Principles: Conditionals - Part 1 Boolean Expressions - Video As a class watch the video on Boolean expressions.

Journal: Have students add the following words and definitions to their journals: Boolean Value and Boolean Expression.

### Assessment: Check For Understanding

Check For Understanding Question(s) and solutions can be found in each lesson on Code Studio. These questions can be used for an exit ticket.

Question: Can a computer evaluate an expression to something between true and false? Can you write an expression to deal with a "maybe" answer?

## Standards Alignment

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

AP - Algorithms & Programming
• 2-AP-10 - Use flowcharts and/or pseudocode to address complex problems as algorithms.
• 3A-AP-15 - Justify the selection of specific control structures when tradeoffs involve implementation, readability, and program performance and explain the benefits and drawbacks of choices made.

#### CSP2021

AAP-2 - The way statements are sequenced and combined in a program determines the computed result
AAP-2.E - For relationships between two variables, expressions, or values: a. Represent using relational operators b. Evaluate expressions that use relational operators.
• AAP-2.E.1 - A Boolean value is either true or false.
AAP-2.F - For relationships between Boolean values: a. Represent using logical operators. b. Evaluate expressions that use logic operators.
• AAP-2.F.5 - The operand for a logical operator is either a Boolean expression or a single Boolean value.