⌂ Home

Lesson 1 — Saying and keeping

Step 1: your first program

Every programmer's first program, in every language, says hello to the world. Here is yours. Type it into a file called hello.nifla:

Runs right here, in your browser.

The book says it answers:

Hello, world

Now run it:

./nifla hello.nifla

and the machine answers: Hello, world.

Stop and notice what just happened, because it is the whole shape of programming: you wrote an instruction; the machine followed it exactly. say is the language's word for speaking — hand it a value and it prints the value and a new line. The words between the double quotes are text: written words kept as a value.

Notice how little ceremony there was: no setup, no compiling, no waiting — write it, run it, read what it says. That quickness is the JavaScript half of Nifla's promise, and the early lessons live there. The other half is waiting in Lesson 8, and it is worth the walk.

Your turn. Make the program say your own name instead. One word changes.

The worked answer — try yours first, then peek
Runs right here, in your browser.

The book says it answers:

Tyler

Step 2: keeping a value

A program that only repeats what it was told is a parrot. Programs get interesting when they keep things. let gives a value a name:

Runs right here, in your browser.

The book says it answers:

Tyler

A name with a value kept in it is what programmers call a variable. Think of it as a labeled shelf: the label stays, and what stands on the shelf can change. After let, the name can be used anywhere the value could.

Your turn. Keep the text "Shalom" on a shelf called greeting, then say what is on the shelf.

The worked answer — try yours first, then peek
Runs right here, in your browser.

The book says it answers:

Shalom

Step 3: building a sentence

Joining text with + speaks the other side into the text, whatever it is. That is how a program builds a sentence out of pieces — some kept on shelves, some written on the spot:

Runs right here, in your browser.

The book says it answers:

I am Tyler.

Your turn. Keep a town on a shelf called town — any town you like — and say the sentence "I live in " followed by the town and a full stop, all in one say.

The worked answer — try yours first, then peek
Runs right here, in your browser.

The book says it answers:

I live in Washington.

Step 4: numbers, and a shelf that changes

Numbers are kept the same way, and reckoned with +, -, *, and /. And a shelf's contents can be replaced with a plain =:

Runs right here, in your browser.

The book says it answers:

10585
30

Read the middle line slowly: years = years + 1 takes what is on the years shelf, adds one, and puts the answer back on the same shelf. (The 10585 is a small honest lie worth noticing: 29 × 365 counts the years in days without leap days. Programs reckon exactly what you tell them to — no more, no less. Saying precisely what you mean is most of the craft.)

Your turn. Keep the number 7 on a shelf called loaves. Say the shelf doubled, then put three more loaves on the shelf and say the shelf again.

The worked answer — try yours first, then peek
Runs right here, in your browser.

The book says it answers:

14
10

The ledger grows: one gift, said out loud

Here is the first piece of the course's project. A giving ledger is a little book that records gifts — who they went to, and how much, kept in exact cents so nothing is ever rounded. (A real tally this book's first reader keeps works exactly so.) Its first piece is just one gift, kept and said:

Runs right here, in your browser.

The book says it answers:

Feeding America: 620 cents

Notice the number cents was spoken into the sentence by the +, exactly as name was. That one line — a name, an amount, a sentence — is the seed of the whole ledger.

Your turn

Keep your own name and the year you were born on two shelves. Say your name, then work out — from the year on the shelf, not from a number you reckon in your head — how old you turn in 2026, and say that.

The worked answer — try yours first, then peek
Runs right here, in your browser.

The book says it answers:

Miriam
36

You can now…

what the shelf holds with =;

numbers into it as you go;

Two small things to carry forward: lines that begin with // are comments — notes to the reader that the language steps over. And a name made inside a pair of braces { } belongs to that stretch of the program and is not seen outside it. You will meet braces in the very next lesson.

---

← All lessonsLesson 2: Deciding and repeating →