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 more complicated who 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.

  1. If it isn’t open already, open your U1L2-Gossip project.

  2. Find more complicated who 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.

  3. Here is the code for more complicated who. There are two new things in it: pick random and if else. more complicated who {
if (pick random (1) to (4)) = (3) {
report (join (who) (' who') (does what) ( ) (who))                                                                                          
} else {
report (who)
}
}

    1. Find pick random (1) to (10) in the green Operators palette, and click it several times. What does the random block do?
    2. Talk with Your Partner In the more complicated who block, what happens if the pick random block picks 3? What if it picks 4?

: 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 number, 5 + (4 * 3), or join (who) ( ) (does what) ( ) (who)).
  • 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, 5 + (4 * 3) will be evaluated to 17.

The expression pick random (1) to (10) would be written as

RANDOM(1, 10)

or RANDOM(1, 10). Every time you run this code, you will get a different random number between 1 and 10.

  1. Create a new block complicated gossip that is similar to gossip but that uses more complicated who instead of who. (You can choose which who to replace, or you could replace both.)

  2. Change the script for Sprite to use complicated gossip instead of gossip. Run your code, and fix any problems.

Save your work

Making a Block Call Itself

  1. Edit more complicated who. Replace one of the who blocks with a fresh copy of more complicated who that you drag in from the palette. Click more complicated who enough times to see how it has changed.

  2. Discuss the the change in behavior with your partner, and explain what you think is causing it.

  1. 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.

  1. Make more complicated who give the more complicated response three out of four times instead of one out of four times.
  2. What happens when you try it out? Was it what you expected? Explain why it happened.