Looping and Boolean Expressions in Scratch
I get a total of 18 class periods with every 6th grader in the building. I choose to spend quite a bit of that time teaching them about the basics of computer programming, using Scratch.
Last week, we explored boolean expressions. I start by having students analyze this program:
I displayed the program just as it is, and asked the students what the cat would say. Some thought he would say “100 < 10”. Some though he would just say “100”. Many were not sure. We ran the program and the cat said “false”. Students said “Oh, I get it! 100 is bigger than 10, it’s not less than 10, so the cat said false!”
I snapped the next block into the “say” and repeated the process. This time the cat said “200”.
I snapped “touching Baseball?” into the “say” block. The students predicted the cat would say “true”, and it did.
We tried the others, and the students made predictions. By now they realized a hexagon-shaped block would yield true or false. Many students understood the difference between “and” and “or”, and how the logic statements could be nested.
Next, we browsed through the looping statements using this program.
For each program snippet, students predicted what the program would do and then snapped it into the program to test it. We extended the conversation by asking what we’d have to do in order to get the cat to start counting at 1, or to only say the numbers from 1 to 11, etc. We asked how to change the first script to get the cat to tumble in a complete circle. For the last script, we wondered why the cat ran and then stopped at the end of the screen.
We looked at looping and “if” blocks, and then I gave the students a challenge to be done with a partner, using the pair programming protocol. They could choose one of the two challenges here:
Pick one of the challenges below and write a program to solve it!
- Write a program in which a cat, in the lower left corner, has to draw a set of stairs to reach a butterfly friend, in the upper right corner.
The cat should ask for the height and width of each stair. Store these as variables.
Draw the stairs using a loop. If you get to the butterfly, you win! If you reach the edge instead, you lose!
For an advanced challenge, write your program so that the cat and the butterfly start in random locations at the start of the game.
2) Create a guessing game similar to the game we played with the robot. Have a creature ask you how old it is. If your guess is too high, say so. If your guess is too low, say so. If you’re correct, then you win! Keep trying!
For advanced challenges, give yourself only 10 guesses to get the right answer. Also, have the creature set its age to a random number at the beginning of the program.
Students were really excited to tackle the challenges and made some creative and fun programs. I wanted to take it in a direction where we analyze the best strategy for winning each game. What should you guess if you want to win the age-guessing game in as few guesses as possible? Can you look at the position of the cat and butterfly and estimate width and height values of the stairs that would win? I still hope to bring these up next week.
These were some of the programs kids submitted.
EAT THE BANANA has some great features and really causes you to have to develop a strategy to get stairs to reach the bananas.
This one places the cat randomly at first and does a good job determining whether you win or lose!
This squirrel and acorn program had a different twist. You also had to guess how many stairs you were going to make. After drawing the stairs, if you’re touching the squirrel, you win! In addition, their algorithm involved turn-move-turn-move instead of change x – change y – repeat.
Age Guessing program:
GUESS THE DRAGON’S AGE is pretty full featured. It quits if you don’t guess the age in 10 tries! I hypothesized that I could always guess in 10 tries as long as the age was 1-100.
An adorable “Guess how many times I’ve decorated my house” game that doesn’t bound your guesses – devilishly hard.
This cute one had you guess the age of two characters instead of just one. https://scratch.mit.edu/projects/78051070/#editor
I enjoy how Scratch projects often involve artwork, storytelling, and creativity. This student weaves in splash screens and a story about hunting and killing a unicorn into the stairs program.
The challenges were engaging and great for partner work. I wonder if they liked this better than a more open-ended game assignment. I will ask them as the quarter finishes up!