<!--{"pin": "top", "order": 5, "book": ["default", "language"], "continue": true}-->
<!-- TODO review -->

# Learn to Program

Programming from scratch, in TJS, in your browser. You need nothing installed and no
experience.

If you already program, skip this part and start at [Basics](/tjs-basics/), which is written
for working developers. If you come from TypeScript, there is also
[TJS for TypeScript Developers](/TJS-FOR-TS/).

**TJS** is a programming language built on JavaScript, the language every web browser runs.
Nearly everything you learn here is also JavaScript, so it carries over to the programs you
will meet anywhere on the web. TJS adds checks that catch your mistakes and explain them,
which makes it a good first language: when something goes wrong, it tells you.

## How the examples work

Every chapter is full of small programs that run on the page. You can change any of them, and
the result shows beside the program (or above it, on a phone) as you type. You cannot damage
anything: if a change goes badly, the example's undo button or its menu puts the original
back.

Most examples end with a **test**: a few lines that say what the program should do. The line
under the result turns green when the program does it and red when it does not, so you can
see when you have it right. The first chapter, How This Book Works, shows you all of this
before you need it, and Checking Your Work teaches you to write tests of your own.

## What you will learn

There are sixteen chapters, starting with How This Book Works. After it, you learn to:

- put words, headings and paragraphs on a page (Hello, Screen)
- work with numbers and text, and give them names so you can use them again (Values and
  Names)
- write **functions**: named pieces of program you can run as often as you like (Functions)
- write tests that check your programs (Checking Your Work)
- make a program choose what to do (Decisions)
- repeat work without writing it out every time (Repetition)
- keep lists of things (Lists)
- describe one thing with several named parts, such as a person's name and birth year
  (Things with Parts)
- respond when someone clicks a button or types (Responding to the Reader)
- find and fix mistakes (When Things Go Wrong)
- wait for something slow, such as a timer or information fetched from another computer
  (Things That Take Time)

A Calculator puts all of that together into a working pocket calculator. Three chapters
follow it:

- write a function that calls itself, and draw with it (Recursion)
- make a program that runs on a clock and is steered by the keyboard (Time and Events)
- build a game of Tetris, step by step, from everything before it (Tetris)

That is not a watered-down version of programming. Every program you will ever write is made
of the same few ideas: values (pieces of information, like numbers and words), names for
them, decisions, repetition, lists, things with parts, and functions. Real programs use more
of them, in bigger combinations, but nothing fundamentally different.

Some things this part leaves out. Classes (templates for making many similar things) and
modules (splitting a program across files) are covered later in this book. Servers (programs
that run on another computer, not in the page) are not in this book; the tjs-lang website has
a [Full Stack](/tjs-fullstack/) section about them. When you finish Tetris, go on to
[Basics](/tjs-basics/), whose first chapter is Hello TJS. Those chapters are written for people
who already program, so they move faster, but by then that is you.

## How to read this part

Read the chapters in order. Each one uses what came before, and each is short enough to
finish in a sitting.

Do the examples, not just read them. Change a number and see what happens; change it back.
Every chapter ends with a few **Try it** exercises, done in the examples on the page; where an
exercise has a test, the test tells you when you have it. If you get stuck, go back to the
last example that made sense and change one thing at a time. The exercises matter more than
the prose: reading about programming teaches you about as much as reading about swimming.

Expect to make mistakes. Programmers make them all day; the skill is noticing and fixing
them quickly. When you make one, TJS tells you what went wrong and where: for example, that
you gave it a word where it needed a number. You will see those messages often, and by the
end of the part you will read them the way you read a road sign.

For a one-page overview of the whole language, see [TJS: Typed JavaScript](/tjs/), the quick
start on the tjs-lang website. It is not part of this book and is written for programmers.

<!-- prettier-ignore-start -->

<!-- toc -->
- [How This Book Works](/how-this-book-works/)
- [Hello, Screen](/hello-screen/)
- [Values and Names](/values-and-names/)
- [Functions](/functions/)
- [Checking Your Work](/checking-your-work/)
- [Decisions](/decisions/)
- [Repetition](/repetition/)
- [Lists](/lists/)
- [Things with Parts](/things-with-parts/)
- [Responding to the Reader](/responding-to-the-reader/)
- [When Things Go Wrong](/when-things-go-wrong/)
- [Things That Take Time](/things-that-take-time/)
- [A Calculator](/a-calculator/)
- [Recursion](/recursion/)
- [Time and Events](/time-and-events/)
- [Tetris](/tetris/)
<!-- /toc -->

<!-- prettier-ignore-end -->
