CricketScript Lesson 6 of 11 · Bowl one  |  Course

Bowl one

A function takes inputs. A bowler takes a speed and a length.

A bowler doesn't just have pace — they have a plan. A delivery is described by two things: how fast (speed in km/h), and where it lands (the length). Fast and short is a bouncer. Slow and full is flighted. A yorker lands at the batter's feet whatever the pace.

TypeScript handles that with multiple parameters. The signature bowl(speed: number, length: Length): string names each input and its type. Pass them in order. Skip one, or pass the wrong type, and the compiler stops you before you ever bowl.

Set a speed and pick a length below, then press Bowl. Watch the ball arrive and the function return its verdict.

Choose a speed and a length. Then bowl.
VS AS
'Medium good'

Two parameters, one contract.

bowl takes a number and a Length, returns a string. Both arguments are required, and each is checked against its declared type.

type Length = 'short' | 'good' | 'yorker';

function bowl(speed: number, length: Length): string {
  const pace =
    speed < 120 ? 'Slow' :
    speed < 140 ? 'Medium' :
    speed < 150 ? 'Fast' : 'Express';
  return `${pace} ${length}`;
}

bowl(130, 'good');  // 'Medium good'

// TypeScript would catch this:
// bowl(140);  // Expected 2 arguments, but got 1.

Two parameters, one signature.

You just called a function with two arguments. Speed had to be a number. Length had to be one of four strings (a union from last lesson). The signature bowl(speed: number, length: Length): string guarantees all three — both parameter types and the return type.

TypeScript validates each argument independently: pass a string where a number's expected, or forget an argument entirely, and the compiler stops you before the code ever runs. Functions with multiple parameters describe richer behaviours — a delivery isn't just speed, it's speed and length, like a function.

Lesson 7 — Helmet on? →
Reading a paid lesson? The rest is right here.

This is one of 9 paid lessons. Lessons 1 and 9 are free previews if you want to sample first — otherwise the full course unlocks in one click.

$15worldwide · ₹625India (50% off)
Unlock all 11 lessons + bonus →
30-day money-back guarantee · Try Lessons 1 and 9 free first if you'd rather
Made by one person, not a company. Questions: hello@cricketscript.dev