Operation Manual
A beginner’s guide to Scratch
30
Each time we use this program the country variable will be set to a letter. But the
next time we use the program, we want the country variable to be empty. So we
“empty” it by setting it to “0”, ready for the next user.
QUESTION: Study the script. Can you work out what it will do when the program
is run?
As the cat asks questions, the dog’s answers are stored in the two variables
“holiday” and “age”. The script will use these later.
Now for the intelligent part: the conditional statement. We are going to find out if
the dog wants to go on holiday. Time to think logically: the dog will either answer
“yes” or “no”.
We need to find a way of letting the cat know the dog’s answer and of prompting
the cat to act on that answer.
From Control in the Blocks Palette, select an “if” block.
Notes:
You will also need an operator block from Operators to test the input. Grab the
“equals” operator (“[ ] = [ ]”) from the Blocks Palette.
From Variables in the Blocks Palette, drag and drop the “holiday” variable into the
left-hand side of the operator and type “no” into the other side.
Finally, we drag and drop the operator block onto the “if” block.
Now, from Looks place the block “say [Hello] for [2] secs” inside your “if” block –
that is, in the “bracket” cut into the side of the block, so that the “if” block
surrounds it. Change “Hello” to “OK, no holiday for you!”.
But hang on a second, what if the dog does want to go on holiday? Our “if” block
doesn’t allow us to include a possibility for a “yes” answer.
If the dog does want to go on holiday something else must happen. We need to
replace our “if” block with an “if/else” block.
The code to find
out if dog wants
to go on holiday