Page 5: Adding Variety to Gossip
Unit 1, Lab 2, Page 5
On this page, you will improve your program so that sometimes the sentences are a bit longer and more complex.
The block has been built for you (look through the blocks to find it) (hint: what colour is this block? where are all blocks of that colour contained?). It randomly chooses 1, 2, 3, or 4, and if that number is 3, then it reports something more complicated than
who
. Otherwise, it reports who
, just as before.
If it isn’t open already, open your U1L2-Gossip project.
Find
in the red Lists palette, drag it into the scripting area, and click on it enough times to see how it’s different from
who
.Here is the code for
more complicated who
. There are two new things in it:pick random
andif else
.- Find
in the green Operators palette, and click it several times. What does the
random
block do? In the
more complicated who
block, what happens if thepick random
block picks 3? What if it picks 4?
- Find
: Expressions and Values
- An expression is a either a constant value (such as “4” or “winter”) or a call to a reporter block including its inputs (such as
,
, or
).
- Expressions are evaluated to produce a single value (a value can be a number, a string, a sprite, a costume, a script, a list—anything). For example,
will be evaluated to 17.
The expression would be written as
RANDOM(1, 10)
or . Every time you run this code, you will get a different random number between 1 and 10.
Create a new block
that is similar to
gossip
but that usesmore complicated who
instead ofwho
. (You can choose whichwho
to replace, or you could replace both.)Change the script for Sprite to use
complicated gossip
instead ofgossip
. Run your code, and fix any problems.
Making a Block Call Itself
Edit
more complicated who
. Replace one of thewho
blocks with a fresh copy ofmore complicated who
that you drag in from the palette. Clickmore complicated who
enough times to see how it has changed.Discuss the the change in behavior with your partner, and explain what you think is causing it.
- Make Sprite(2) occasionally give a more complicated reply.
Purple “Take It Further” boxes have more challenging activities that are not required. If you finish everything else on the page early, try these instead of jumping ahead to the next page.
-
Make
more complicated who
give the more complicated response three out of four times instead of one out of four times. - What happens when you try it out? Was it what you expected? Explain why it happened.