Say Hello to Snap!
In this activity, you'll play greet the user in various languages and with fancy text.
I don't know the expected class time per activity. I assume (hope) it is less than one full class period. But this is the kids' fourth activity and the first time they get to be
(not pretend to be) a programmer. Activity 3 was account creation and UI. Account creation could
be accounted for (ahem) by the teacher in advance, allowing kids (in a suitably designed microworld) to have a real experience in programming immediately on the first day and even save it, and later
learn the picky details. The original UCB hoc click-on-Alonzo project, pre-EDC, was a great model. A single palette with a limited set of blocks, and suggestions about what to accomplish next but leaving the student the nice puzzle of figuring out how, which blocks to use. That particular project was not functional-first, but Sparks could invent one. Just saw 1.2.1, where you do exactly what I'd hoped to see first thing. If you start with that the very first day
the immediate experience will be an experience doing something impressive with functional programming, leaving details and formalities for later. (See also the model of BJC's gossip project https://bjc.edc.org/bjc-r/cur/programming/1-introduction/2-gossip-and-greet/2-gossip.html
which, except for using the sprite to say the result, was entirely functional.) --PG
Loading a Snap project
For each lab, we'll provide you with starter projects that you can save to your account.
When you open the project, you'll see this single block in the "Scripts" area (the central space of the Snap! window):
- Type a name in the blank slot, and click the block to see what happens. Did you see a bubble pop-up?
- Change the name, and click the block again.
Every Snap! program is made up of blocks like
say hello that tell the computer what to do. This block says hello to someone in a specified language.
- Choose a different language from the dropdown menu that says "English," and click the block again. What changed about the bubble this time?
You just saw how changing the inputs to a block changed its output. Now let's introduce some terminology.
There are multiple types of blocks in Snap. This
say hello block is a reporter block. That means that it does some sort of computation and then "reports" the result. When you click it, the computer runs its code, and you see the reported result in a bubble, like this:
- Many blocks, like
say hello, accept inputs that customize what they do, and those inputs show up as spaces you can edit. The
say hello block accepts two inputs, a name and a language. You can change the inputs to change the output (in this case, the reported greeting).
Blocks Within Blocks
There are lots of blocks in Snap!, and you can even make your own. For this first project, most of the blocks are hidden, but you should see a block in the palette on the left.
- Drag the
somewhere separate from the
say hello block in the Scripts area.
- Type a name into the
fancy block, and click it to see the output. Does it look… Ƒᵃ𝐍𝓬у?
Snap! is called Snap! because you can snap blocks together. Drag that
fancy block into the first input slot of the
say hello block, replacing the name from before, and click the block to see the output.
You can tell where the block you are dragging will drop when you let it go because the input slot where it will land will be marked with a white box. Click for a picture.
- You should see a personalized greeting to a fancy version of the input name in the chosen language.
That's the power of reporter blocks! You can use the output of one block as the input to another block, making a chain of computation.
Saving Your Project
- Make sure you are logged in to Snap! by checking that your name appears in the Snap! Cloud menu (), and logging in if necessary.
- Save this project to your Snap! account by choosing "Save" from the Snap! File menu (it looks like a piece of paper with a corner folded: ).
Be sure to save your projects after an important change and, if you are using a shared computer, whenever you're done for the day.
In this activity, you learned to run a block by clicking it, you changed the inputs to the
say hello and
fancy blocks and observed their outputs, and you dragged the
fancy block into the
say hello block so that the output of one block could be used as the input of the other.