Code Haven Week 4

 

Topics: Variables, Conditionals

Topics: Variables, Conditionals

Week 4 Overview

Objectives

  • Introduce the concept of variables
  • Practice using variables in Scratch
  • Ensure that students know when to use variables in their coding

Materials and Resources

Lesson Plan Overview

View our detailed lesson plan here.

  • Introduction (10 min): Review loops and conditionals
  • Unplugged Activity (10 min): Mad Libs activity!
  • [Optional] Live Coding (5 min): Demonstrate variables in Scratch, use “ask” and “join” blocks
  • Worksheet (30 min): Log into Scratch accounts and work on the worksheet
  • Wrap up (5 min): See how variables fit with the maze activity

Worksheet

Part 1: Scratching an Itch!

Let’s have the Scratch Cat keep track of how many times we hover over him!

image #1

- First, set up the program so that it starts when we click the flag and runs forever. We should also set the variable to 0 at first.

- Next, create a conditional that runs if the pointer is touching Scratch.
    
- Finally, complete the conditional to make the variable increase, and then wait a second!

Here’s the Block Bank:

bb #1

Part 2: Count Scratchula!

Scratch is already keeping track of how many times we touch him, but he should be able to tell us how many!

When we press the spacebar, Scratch should say “You touched me ___ times!” and then reset his count.

image #2

- Create a new conditional that runs if we press the spacebar!

- When we do, Scratch should say how many times we touched him, and then reset the variable.

Here’s the Block Bank:

bb #2

Part 3: A Visit to Dr. Scratch!

The Scratch cat is hungry! Eating cake makes him more powerful, but running into a pufferfish hurts him.

Let’s keep track of his health level!

image #3

- First, set up the program so that it starts when we click the flag and runs forever. We should also set Scratch’s health variable to 10, and make him draggable.

bb #31

- Next, create two conditionals that run if Scratch runs into the cake or the pufferfish.
- Finally, complete each conditional to make the variable increase or decrease.

bb #32

- Add another conditional to have Scratch say “Power up!” if his health gets too low. He should then reset his health to 10.

bb #33

Challenges:

Can you change your drawing so that it uses two loops?

How else can we use randomness to make your drawing even more unique?