Beginner Conditionals
Contents
Introduction
We often want to be able to “conditionally” do things in our programs – we want to be able to say “if this thing is true, then do X but if this other thing is true, then do Y.” It’s like when we wake up in the morning – “if it’s raining outside, then I take an umbrella, but if it’s sunny, then I wear sunglasses.” We can do things conditionally in our programs using if statements and if/else statements.
What is it?
A conditional is a statement that can only run under certain conditions.
Think about it!
If you’re hungry after school, then you eat a snack. What other things do you do during the day under certain conditions?
Activities
Bee Conditionals
In the Bee Conditionals puzzle on Code.org , you’ll use conditionals with the bee to help deal with some mysterious purple flowers. We don’t know if those flowers have nectar or not, so you’ll need to use conditionals to make sure that you collect nectar if it’s there, but you don’t try to collect nectar from a flower that doesn’t have any.
The If/Then Game
Close your laptops, stand up and practice making conditional statements with everyone on your team.
How to play : For every round of the game, there is one Coder and everyone else is a Computer. The Coder stands in front of the Computers and gives them his/her command. If I _________ (fill in the blank), then you __________ (fill in the blank). For example, the Coder can give the command: “If I turn in a circle, Then you jump up and down.” Coders can command the computers to do something different than they are doing or the same thing. So, be sure to listen to the command and not just watch the coder.
Add a challenge
- If-Then-Else statements. For example, the Coder commands: “ If I raise my right arm, Then you raise your left arm, Else raise your right foot.” So, if the Coder just stands there doing nothing, Computers should all be raising their right foot.
- Eliminations. Computers should “break” and sit down when they don’t follow commands correctly. The last Computer standing wins.
Maze Project
Any block in Scratch whose label says “if,” “when” or “until” can be used to create a conditional statement. With it we can instruct a sprite to say hello only if the user has pressed the mouse button:
To get some experience using conditionals in Scratch, remix the Maze Starter Project. You’ll see the project has an example of how to use conditionals and a chance for you to try it yourself.
Remix
What is a remix?
A remix is a changed and shared version of an uploaded project in Scratch. In general, remix is what musical artists call changing a song by using the same tune but changing the style.
Many Scratch users find remixing fun and interesting, because it allows then to learn from, experiment with and add on the work of other users. As of December 2015, about 30% of all recently shared projects are remixes.
How do I remix a project?
1. Start on the project page and click on ‘See Inside’.
2. Edit the project however you want. What can you edit? You may want to change or add to the project, including the theme, graphics or scripts.
3. When you’re done editing, click on the orange Remix button, in the top-right of the project editor, to upload the project as a remix from your account.
4. When uploading a remix, give credit to the original creator of the project in the “Notes and Credits”.