L33t Text

If this splits into three pages, any reason not to make it into it's own lab? (That would make it different than the SIGCSE paper though...) --MF, 1/10/23
In this activity, you’ll make your own text processing block by using a new block that tells the program to report specific things in specific cases:
if 'predicate input slot' then () else ()

What is L33t?

In the 1980s, the Internet was mostly text-based. Similarly to how today we use emojis 🦊 🚲 and abbreviations (like LMK or LOL) to embellish messages, early Internet users (and some gamers today) used a modified spelling called leet (meaning, "elite") where certain letters are replaced with numbers that look similar (such as replacing "s" with "5" or "e" with "3").

For example, can you read this text?

1 w4nt t0 g0 t0 5ch001 34rly t0d4y.

You're going to build a l33t block that converts just one specific letter to a number (such as just changing "e" to "3").
l33t (I have dance class at eight on Tuesday.) reporting 'I hav3 danc3 class at 3ight on Tu3sday.'

Your block will need to need to:

You've already learned how to use map to apply a function to every item in a list, and how to use join to join elements of a list into a single text string. The missing ingredient is a letter-changing function.

Consider Page Break Here

And add "Write out a sentence in L33T (on paper)" and then "See id you can read someone elses." exercises to the end of the first page above.

Creating a Letter-Changing Function

  1. Open your "Texting Time" project, if it isn't open already.
  2. Decide which letter of the alphabet you want to change into a number, and create a new change for letter block that takes one input called letter. This block will decide whether to change one letter at a time. For example, if you were changing "e" to "3", your new block would look like this:
    change e to 3 for letter (letter) hat block with report () attached

    Click for a reminder about how to create a new block.

    1. Right-click (or control-click on a Mac) in an empty spot in the Scripts area and choose "make a block..."
    2. Choose the color for your block.
    3. Type the title text for your block (for example, "change e to 3 for letter").
    4. Select the shape for your block.
    5. Click "OK."

    Click for a reminder about how make a block take an input.

    1. Hold your mouse pointer at the point in the text text of the hat block in the block editor where you want the input slot to appear, and click the plus sign that appears.
    2. Type the name of the variable you want to add (such as letter), and press "OK."
    3. To use this new local variable in your code, drag off a copy from the hat block, drop it into your code.

You can use the if 'predicate input slot' then () else () block to decide which thing to report. The if then else block takes three inputs:

: Predicate and Conditional

A predicate is a hexagon-shaped reporter that asks a true/false question such as these examples:
8 > 7 reporting true 6 > 7 reporting false

A conditional is a block that controls the code based on a true/false condition (the predicate). The if 'predicate input slot' then () else () block is an example of a conditional.

  1. Use if then else to write code for your change for letter block that will test whether the input letter matches the letter you want to change into a number, and if it does, reports the number, and if it doesn't, reports the input letter without changing it.
  2. Test your change for letter block with your chosen letter and with other letters.
    change e to 3 (l) reporting 'l' change e to 3 (e) reporting '3' change e to 3 (t) reporting 't'
Consider Page Break Here

Mapping the Letter-Changing Function Over All the Letters

  1. l33t (text) hat block with report () attached Now, create another new block called l33t that takes one input called text, splits that input text into a list of letters, applies your letter-changing function to every item in the list, and joins the letters back together.
  2. Click below for support with:

  3. Test your l33t block for different words and phrases. It should report the exact same word or phrase as the input except that the one letter you choose should be replaced by the number you chose to replace it.
    l33t (I have dance class at eight on Tuesday.) reporting 'I hav3 danc3 class at 3ight on Tu3sday.'
  1. Create additional letter-changing functions and try them in your l33t block. For example:
    change s to 5 for letter () l33t (I have dance class at eight on Tuesday.) reporting 'I have dance cla55 at eight on Tue5day.'
  2. Duplicating a Block

    To easily make a new block that is similar to your letter-changing function (such as change e to 3 for letter), you don't need to start all over again. Instead, just right-click on the block name in the palette on the left and select "duplicate".

    That will create a new block (such as change e to 3 for letter (2)) and open it for you in the block editor. You can click the text in the hat block to change the name. Then create the code for your new block.

  3. Here are some other ideas for ways to extend your project:
    • Replace a letter with an emoji.
    • Replace a letter with multiple letters. For example:
      change x to ks for letter ()
      l33t (The fox is in the box.) reporting 'The foks is in the boks.'
    • Replace multiple letters at once by nesting multiple letter-changing functions.
In this activity, you learned how to use the conditional if then else together with a predicate and the map block to test each item in a list.