To make progress with Tic Tac Toe, your program needs to control which action happens at which time. Control blocks are the topic of this page. You will also start a new mini-project about English words and simple phrases that will give you practice with conditional statements and with breaking complex tasks into meaningful parts.
To create realistic dialogues, a program needs to adjust some words to fit others. For example, it needs to know when to use a or an. A peach or an peach? A apple or an apple?
To decide, it needs a predicate that tests the next letter to see if it's a vowel. It should work like this:
There are many ways to create a block like this. Here's one way, started for you.
vowel?
outputs only true
or false
, remember to choose the hexagonal predicate shape when you first define the block.
Complete it, test it, and save it for future use.
use "a" or "an" with (noun)
, that takes a word as input and reports either "a" or "an."
join "a" or "an" with (noun)
that works like this:You will need to use with two inputs. The block automatically shows a slot for only one input, but you can use the arrows
to increase or decrease the number of inputs.
The definition of
even?
needs only one if
statement, because all integers are either even or odd. If the boolean expression (n
mod 2 = 0
) evaluates to false
, the number is not even, so it must be odd.
The way vowel?
was approached above used several if
statements because it tested for several conditions.
n
mod
m
reports the remainder when n
is divided by m
. That remainder is 0 only when n
is a multiple of m
. So, direction
is a multiple of 60°. So, the predicate true
only when direction
is 0, 60, 120, 180, 240, or 300.
When the sprite's direction is not a multiple of 60,
reports a number other than 0. For example, if the sprite's direction is 127°,
reports 7.
When the sprite is pointing in direction 90, reports 0.
In how many other directions will the predicate report
true
?
if else
and repeat until
) control each of these scripts. Construct and analyze them with your pair programmer, experimenting with the conditions until you are sure you can explain exactly how this code does what it does.
turn 2 degrees
or turn 7 degrees
instead of turn 1
?