3.7 IF-ELSE

Students search for boolean operators and conditional statements (known by their pointed edges), in a Scratch Scavenger Hunt.
Students compare IF-ELSE and NOT statements in a challenge where the background changes as a sprite moves across the stage.

OBJECTIVES:



OBJECTIVES: By the end of this lesson, students will:

    • identify Boolean operators.

    • identify Conditional statements.

    • compare IF_ELSE and NOT statements.

    • discover that there is more than one way to code.

TEACHER RESOURCES:

Standards

    • CSTA 2-AP-12: Design and iteratively develop programs that combine control structures, including nested loops and compound conditionals.

    • CSTA 2-AP-13: Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.

CSTA

DO NOW:

No "Do Now". Instead there is a scavenger hunt and a project activity.

    • Scavenger Hunt Students work with a partner, searching for boolean commands in scratch. Boolean commands are hexagons with pointed edges.

    • Video reference

        • There are 8 Boolean operators denoted by the pointed edges. Can you find them? Test them out!

        • There are 4 conditional statements in scratch, that need pointed edge boolean operators. Can you find them?

        • There is one boolean event in scratch, can you find it?

TakeAways:

      • Conditions in scratch are hexagon blocks with pointed edges that only fit into conditional statements.

      • Conditions evaluate to True of False.

      • Conditions allow your program to branch down different paths. If True, do one thing, If False do another thing.

Mini-Lesson (5-10 minutes)

Review the flow of a program through two conditional statements: If and IF-ELSE.

Notice that the If Statement has an action that happens only If raining is True, but that the IF-ELSE Statement has an action If it is raining, or If it is Not raining.
Stress that the ELSE portion is what happens, if the conditional statement is NOT true, i.e FALSE.

Optional Student Document

Project (20-30 minutes)

TEACHER GUIDANCE:

Project: Students use a Starter project. Finished Project

The coding element is simple, with all code required to complete the project given in script starter project. However the concepts are complex.

      • Students need to know the X Y Grid. That there is a negative X space and a positive X space.

      • Students need to know the "greater than" operator and that it evaluated to either True or False.

      • For the Spicy challenge, students need to identify the boolean operator NOT
        e.g. NOT(2=2) equals NOT (TRUE) which evaluates to FALSE.

It is useful for students to see code written in different ways. In this lesson, the spicy challenge solves the project in a different way.

      • The extra spicy challenge also looks at a third way to solve the same problem!

      • Students should come to realize over the duration of this course, that there are many different ways to write code.

Close-Out (5 minutes)

Discuss the following questions:

      • Evaluate both statements below and discuss what happens in each case, if Raining and if not raining? Optional Student Document.

If the IF condition is FALSE, the code inside [Take an umbrella] will be skipped.

If it is raining ( condition is TRUE) then both code segments generate the same result. [Take and umbrella and go to the center of the stage(0,0)

If it is not raining, the code segments differ. With the IF-ELSE code, you will also take your sunglasses.