1 of 33

Upper Elementary

Computer Science

Introduction to Conditionals

2 of 33

Objective

  1. Students will be able to explain what a conditional is in programming.
  2. Students will be able to create a program that uses if/then blocks in Scratch.

3 of 33

Conditional: A command that tells a program how to make a decision if something is true or false

Vocabulary

?

4 of 33

Boolean: A value that can only be true or false

Vocabulary

5 of 33

Review

6 of 33

How do you decide whether to wear a jacket to school?

7 of 33

How do you decide whether to wear a jacket to school?

  • Is it cold outside?
  • Is it rainy?
  • Is it cold in the classroom?

8 of 33

How do you decide whether to wear a jacket to school?

You make a decision based on if conditions are true. If it’s cold, you wear a jacket. If it’s not, you don’t.

9 of 33

Conditionals in Programming

In programming, we use conditionals to help computers make decisions. A conditional is based on a condition that is either true or false.

Is it cold?

Yes/True

No/False

A value that can only be true or false is called a boolean.

wear jacket

don’t wear jacket

10 of 33

Here’s an activity to practice conditionals in everyday life.

We use conditionals to make decisions all the time.

Let’s make some decisions with conditionals!

11 of 33

Complete the sentence:

If it’s raining, __________.

12 of 33

Complete the sentence:

If it’s hot outside, __________.

13 of 33

Complete the sentence:

If my room is messy,

__________.

14 of 33

Using conditionals in Scratch.

Find the "if/then" block in the Control section.

15 of 33

Using conditionals in Scratch.

The condition goes in the diamond space.

Use the blue Sensing blocks to check the condition.

16 of 33

Using conditionals in Scratch.

If the condition is true, the blocks inside the "if/then" block will run.

Is the sprite touching this specific color?

Yes/True: Say “I like purple.”

No/False: Do nothing.

17 of 33

Using conditionals in Scratch.

Important note: the computer only checks the condition once.

What do we use if we want to repeat a command multiple times?

18 of 33

Using conditionals in Scratch.

Adding a “forever” loop around the conditional will keep the code running inside of it until the program stops.

19 of 33

We will make a beach scene program with conditionals!

20 of 33

Guided Practice

21 of 33

Program the cat sprite to move.

22 of 33

Add an “if/then” conditional.

23 of 33

Add a “touching color” block.

24 of 33

Add a “say” block to show when the condition is true.

25 of 33

Test your program.

  • Is your code working as expected?

  • What changes could be made to your code?

26 of 33

Add a “forever” loop.

27 of 33

Program the cat to say “Let’s Play” if touching the Karel sprite.

28 of 33

Independent Practice

29 of 33

Add more to the beach scene.

  • Add a new sprite to the scene.
  • Add a conditional for the cat sprite to do something if touching the new sprite.
  • Add a conditional that has the cat sprite do something if it touches another color in the beach scene.

30 of 33

Extensions

31 of 33

If you have more time…

  • Add more sprites to the scene.
  • Add a conditional for the new sprite to do something if touching other sprites.
  • Add a conditional that has the new sprite do something if it touches another color in the beach scene.

32 of 33

Showcase!

33 of 33

Reflection

Can you give an example of a conditional from our lesson?

Can you think of other situations in your daily life where you use if/then logic?