Week 10: Functions

C# code typing course. 19 wpm, 93% accuracy.

A function is a named piece of code you write once and call whenever you need it. When you define one, you list the values it expects inside round brackets. These values are its parameters, and commas separate them. This week you combine the round brackets you already know with the comma,

What you will learn

A function definition puts the return type, the name and the parameters on one line. The body follows between curly braces:

static int Topla(int a, int b)
{
    return a + b;
}
  • static int Topla(int a, int b) defines a function that takes two whole numbers and returns a whole number. The comma between the parameters separates them.
  • return a + b; adds the two values and sends the result back to whoever called the function.

This week’s symbols on the US English layout:

  • (: press 9 with Shift. Hold Shift with the opposite pinky (the left pinky) and press 9 with the right ring finger.
  • ): press 0 with Shift. Hold Shift with the opposite pinky (the left pinky) and press 0 with the right pinky.
  • ,: press the , key with the right middle finger.

Technique tips

  • Think of the parameter list as one unit between the two brackets. The commas inside it separate each parameter.
  • Type the closing bracket right after the opening one, then fill in the parameters. This keeps a definition from being left unfinished.
  • Return to the home row after each symbol. Short, regular returns keep your rhythm.
  • Enter fills in the next line’s indentation when the function body opens. Continue inside the braces without retyping the indent.

Lessons

  1. Learn (10 to 15 minutes): Watch the demo for (, ) and ,, notice which bracket needs Shift, and type the definition line several times.
  2. Practice (10 to 15 minutes): Type this week’s function definitions. Keep the commas and brackets in the same places on every line.
  3. Review (10 to 15 minutes): Take the two-minute test. Note which symbol caused mistakes and focus on it in the next lesson.

This week’s goal

The goal this week is 19 WPM with 93 percent accuracy. Stars work like this: finish the lesson for 1 star, reach 93 percent accuracy for 2 stars, and reach 19 WPM as well for 3 stars. One missing comma or bracket breaks the definition, so accuracy comes first. Speed follows as the pattern becomes familiar.

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

    14 minutes

    Start

All weeks