Start

Learn to program

A course for people who have never written a program, in thirteen short lessons you do in the browser, each with one idea and one small exercise.

Programming is telling a computer what to do, one small step at a time. In this course you write real programs from the first lesson on, right here in the page. Each lesson takes three to five minutes and teaches one idea.

Every lesson has an example you can change and run, a small exercise with a hint and a solution, and one line to remember. Nothing to install: when you want to run programs on your own computer, the last lesson shows how.

Who this is for#

For anyone who has never programmed, or tried once and gave up. You need no maths beyond adding and multiplying, and no words from computer science: every new word is shown before it gets a name.

If you already know another programming language, the guide is faster: it starts from what you know and shows what is different.

  1. 1Your first programA program is a list of instructions that the computer follows from top to bottom, and print is the instruction that shows a line of text.
  2. 2Names for valuesGive a value a name with const and use the name instead of the value; write var instead when the value has to change later.
  3. 3Numbers and textPrograms calculate with + - * and /, join text with +, and every value has a type that says what kind of value it is.
  4. 4Making decisionsWith if and else a program does one thing or another, depending on a question whose answer is true or false.
  5. 5Repeating thingsA for loop runs the same lines once for every number of a range, and a while loop runs them as long as a question is answered yes.
  6. 6ListsA list holds several values in order, a loop goes through them one by one, and giving a list a second name makes a copy.
  7. 7FunctionsA function gives a few lines a name, so they can run again with a different value each time, and it can hand a result back.
  8. 8Your own typesA type of your own bundles values that belong together, like the name and the age of a pet, and can have functions of its own.
  9. 9One of several casesA type can list the cases a value can be, like sunny or rainy, and match does one thing per case and makes sure no case is forgotten.
  10. 10When a value might be missingWhen a value might not be there - the fourth item of a list with three - the answer says so, and ?? or match decide what happens then.
  11. 11When something goes wrongA function that can fail says so and answers Ok with its result or Fail with the reason, so every failure is handled where it happens.
  12. 12A small projectA reading list that puts every lesson together - a type with cases, a type with fields, a list, a loop and functions - in one program.
  13. 13Where to go nextInstall TorbScript to run programs on your own computer, and pick what to read next - the guide, the reference, or a project of your own.
Esc