Line by Line

A code sample and the steps that explain it. Press a step and its lines light up while its note says what they do; Previous and Next walk the same steps, and Copy puts the code on your clipboard. On a wide screen the steps sit beside the code; on a narrow one they sit under it, one at a time.

request.js
// Create an order with the Example API
const key = process.env.EXAMPLE_API_KEY;
const order = {
item: "starter-plan",
quantity: 2,
note: "Leave at the front desk",
};
const res = await fetch("https://api.example.com/v1/orders", {
method: "POST",
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
body: JSON.stringify(order),
});
if (!res.ok) throw new Error(`Order failed: ${res.status}`);
const created = await res.json();
console.log(created.id);
1 of 4
Load your keyRead the secret key from an environment variable, never from the page.
Describe the orderPlain data: what is being bought, and how many.
Send itOne POST, with the key in the Authorization header.
Read the replyStop on an error status, otherwise use the new order's id.

Demo: the default walkthrough, a request in four steps on the dark palette, with no control changed.

regions.py
import csv
from pathlib import Path
SOURCE = Path("orders.csv")
def read_orders(path):
with path.open(newline="") as f:
return list(csv.DictReader(f))
def total_by_region(rows):
totals = {}
for row in rows:
region = row["region"]
totals[region] = totals.get(region, 0) + float(row["amount"])
return totals
if __name__ == "__main__":
for region, amount in sorted(total_by_region(read_orders(SOURCE)).items()):
print(f"{region:<10} {amount:>10.2f}")
1 of 3
Read the rowsEach line of orders.csv becomes a dictionary keyed by the header row.
Add up each regionOne running total per region, starting from zero the first time a region appears.
Print the reportRegions in alphabetical order, amounts right-aligned to two decimal places.

Alt: a Python script in three steps on a light palette, with a Max height, so the code scrolls inside its own panel; go to the last step and the panel scrolls to its lines.

Create a free website with Framer, the website builder loved by startups, designers and agencies.