Adding an Input to Your Block

Add support for new variadic slot features. --MF, 2/1/22

In this activity, you will make your plural block accept a word as input, join a letter "s" to the end, and report the new, plural word as output.
  1. Add an input slot for the word that will be made plural.

    Hat blocks tell you when a piece of code should be run and what (if any) inputs it takes.
    'plural of (word)' inside a hat-shaped block
    This code will run whenever the plural block is called, and takes one input called word.

    1. Hold your mouse pointer right after the word "of" in the plural hat block, and click the plus sign that appears.
      'plural of' in the block editor showing the plus sign just after the word 'of' in the hat block
    2. Type the word "word," and press "OK."
  2. Code your plural block.
    1. Drag a new join block out of the palette on the left and into the report block.
    2. Drag off a copy of the "word" block from the plural hat block, drop it into the first input slot of join, type an "s" in the second slot, and press "OK." Whatever text is typed into the word input slot of plural will be the first input to join.
      'plural of' in the block editor showing a copy of the 'word' variable being dragged off
  3. Drag your plural of block out of the palette (it'll be at the bottom of the Operators category) into the Scripts area, and test it with different inputs. (For example, if you give it the input "cat," it should report, "cats.") If there are any problems with your block, right-click it, select "edit..." and make sure your code looks like this:
    'plural of' in the block editor with 'report (join (word)('s'))' attached below it
  4. Once your plural block is working, try it with random animal, and finally, drag plural of (random animal) into super short story, and make sure it works as expected.
  5. Your plural block works for more than just animals! Try it with the random job block.
  6. Save your work
The vocab box about abstraction should be cut down considerably. --MF, 2/9/22
: Abstraction

Will they be watching a video on abstraction here? Or does Dan mention it in welcome? It feels so..abstract..here that I wonder what students will take from it. If I wasn't bound to use the term abstraction, I'd probably emphasize the benefit of reuse "When we realize we've developed a useful piece of functionality that we might want to use in other places, we can turn it into its own block." Anyway just musings from your local "abstraction" skeptic, feel free to delete. -- PF 8/20/21

I added your text at the beginning and am open to a Dan video and/or more discussion about teaching abstraction. :) --MF, 8/20/21

When you've developed a useful piece of code that you want to use in other places, you can turn it into its own block. This is a form of abstraction. Abstraction is an important idea in computer science. One kind of abstraction is breaking up a large problem into smaller sub-problems.

For example, instead of putting join (random animal) (s) into an input slot of super short story, you can create a plural of () block and put random animal in its input slot.

This makes your code easier to read, you can use the new block again in other places, and once the block is working, you don't need to think about how it works each time you use it.

In this activity, you created a new block to perform a specific task and used it in your story.