Week 10: Functions

Small Basic code typing course. 19 wpm, 93% accuracy.

A function does one specific job, such as finding the largest of two numbers, and gives back a result. A subroutine is a block you write yourself, starting with Sub and ending with EndSub. Small Basic subroutines take no parameters and return nothing, so you pass values through variables. This week’s goal is to call both kinds correctly, with the right parentheses, and to place commas correctly between values in built-in calls.

What you will learn

This week has three symbols. On the US English layout:

  • (: 9 key + Shift (Shift with the left pinky). Right ring finger.
  • ): 0 key + Shift (Shift with the left pinky). Right pinky.
  • ,: , key, right middle finger.

First, define a subroutine:

Sub SayHello
  TextWindow.WriteLine("Hello " + name)
EndSub

This block defines a subroutine that uses the value in the name variable. It takes no parameters, so the definition has no parentheses.

name = "Ada"
SayHello()

The first line stores a value in name. The second line calls the subroutine. The empty parentheses show that the call passes no values.

Built-in functions use commas to separate their values:

largest = Math.Max(4, 9)
TextWindow.WriteLine(Math.Round(3.6))

The first line finds the larger of 4 and 9, which is 9, and stores it in largest. The second line rounds 3.6 and writes the result, 4, to the screen.

Technique tips

  • Open the parenthesis at the start of each call, type the values, then close it. Build a solid structure first, then gain speed.
  • Press Shift with your left pinky for ( and ). Keep your right ring and right pinky ready for the parenthesis keys.
  • Use your right middle finger for the comma, and put a space after it so the values are easy to read.
  • Write SayHello() with its parentheses even though the subroutine takes no values.
  • Enter fills in the indentation of the next line. Indent the lines between Sub and EndSub consistently.

Lessons

  1. Lesson 1, 10 to 15 minutes: Learn the three symbols. Watch the keyboard demo and type each symbol three times.
  2. Lesson 2, 10 to 15 minutes: Write Math.Max and Math.Round calls. Then define a Sub and call it with SayHello().
  3. Lesson 3, 10 to 15 minutes: Review what you practiced, then take the 2-minute test.

This week’s goal

The targets are 19 wpm and 93% accuracy. Finishing the lessons earns one star. Reaching 93% accuracy earns the second star. The third star also needs 19 wpm. A missing parenthesis stops the call from working, so accuracy comes first.

Symbols this week

The colored keys are the ones you learn this week. The color shows which finger presses the key.

` ~ 1 ! 2 @ 3 # 4 $ 5 % 6 ^ 7 & 8 * 9 ( 0 ) - _ = + Backspace Tab Q W E R T Y U I O P [ { ] } \ | Caps A S D F G H J K L ; : ' " Enter Shift Z X C V B N M , < . > / ? Shift Ctrl Win Alt Alt Gr Win Menu Ctrl

This week’s lessons

Do the lessons in order. Each one ends with a test, and your best result is saved.

  1. Lesson 1: Learn

    New symbols: ( ) ,

    12 minutes

    Start
  2. Lesson 2: Practice

    Practice

    12 minutes

    Start
  3. Lesson 3: Review and test

    Review and test

    12 minutes

    Start

All weeks