Trying it out - Rumour Has It: Building a Function

Objective

After completing this lesson, you will be able to apply the concepts of the previous lesson - Rumour Has It: Building a Function.

Exercise

Your Turn!

Now it’s your turn. Download this document for a recap of the blocks we covered in this lesson and some hands-on exercises for you to explore.

What You Have Learned in This Lesson

Lists

This unit was all about lists.

Lists are a so-called compound data types, meaning they group a set of values into one unit. These values can be numbers, text, other lists or even objects or blocks. You already used a list of objects in the last lesson, when picking a random item from my other sprites, a list of other objects in the project.

Lists are ordered, meaning the order of items stays the same and every item of a list has an index with which it can be accessed. The same value can occur several times in the same list.

You can access, add or delete values from a list with blocks. All the red list blocks can be found in the "Variables" category

The red list blocks can be found in the “Variables” category. Lists are generated with the list block, one new item can be added to the list by clicking on the right facing arrowhead, three items can be added by shift-clicking the arrowhead. Clicking on the back facing arrowhead removes items. Lists can contain different values like numbers, texts, other lists, objects or blocks.

Functions

In this lesson you also learned how to make your own reporter, an oval-shaped blocks that reports back a value.

A function in math takes 0 or more inputs and generates exactly one output. The same input always yields the same output when the function is applied.

In computer science, a function is defined in a broader sense. It is a part of a programming language (in Snap! a block) that performs a specific task and returns a value.

Functions are not supposed to have state or side effects.

To learn more about functions, check out the "Beauty and Joy of Computing" lecture by Dan Garcia.

To create a custom reporter, you just select "Reporter" as the block-type in the "Make a block"-dialog box. Your "Block Editor" will then automatically add a report block to your block definition. The value you put in the input slot of the report block will be displayed in a speech bubble when you evaluate the block.

To create a custom reporter, select „Reporter” as the block shape. Then put whatever the block is supposed to report in the input slot of the “report” block in the block definition.

Loading extra blocks from libraries

Additionally, you got to know how to import thematic libraries with additional blocks.

Go to the file-menu and select "Libraries…" to open a dialog box with all block extensions. Choose the library you want and click "Import" to add the blocks of the corresponding library at the bottom of the palette.

In the upper right part of the dialogue box is a preview which shows all blocks a selected library contains.

Click on the file menu – „Libraries..” to open a browser with all available libraries. Use the search bar at the top to look for a specific one or just scroll through them. You can see the blocks in a library you selected in the preview window on the right. To load the blocks, select a library and press “Import”. The imported blocks will appear at the end of the corresponding category.