Page 43 - Ones and Zeros 4 (Student Book)
P. 43
If Statement
Lesson
Lesson
Fun Time!
Using the ‘if statement’.
Now we’ll add a new script for the main part of the game. The instructions said that we
need to click the space bar to start. So, we’ll need an ‘event’ block to do this. After that,
the blocks you add will contain questions. These questions can be fun and educational!
1 Use the ‘when ‘space’ key
pressed’ block to start the
questions.
2 Now, you have to add your first
question. Use the ‘sensing’ block,
‘ask and wait’.
Type your question.
3 An ‘if’ block is a ‘control’ block.
Select the block, ‘if then else’,
and add it to your script.
4 The green block is an ‘operator’ 1
block. We insert it after the ‘if 2
statement’.
5 We want the ‘answer’ to be 3 4 5
‘apple’, so after we have chosen
the green ‘operator’ block ‘_=50’, 6
we insert the ‘sensing’ block
‘answer’ and in place of ‘50’ we
type ‘apple’. 6
6 The remaining two ‘looks’ blocks
give us the output, depending on
what we choose.
Challenge Yourself!
Making duplicates.
Now you’re going to add four more questions. This time, you don’t need to drag any
blocks. If you right-click on the ‘ask and wait’ ‘sensing’ block, you can choose ‘duplicate’.
The programme will create a copy of the script starting from that block. Drag the copied
script under the blocks you already have and change the questions and answers.
Save the file when you’re done and exit.
41