1
Fork 0
tip-calculator/README.md
Leonardo Devai b3326856db Review and modernize all 42 projects to the updated standard
Pinned 2026 toolchains (Go 1.26, Rust 1.98/edition 2024, Python 3.14 + uv, Node 24,
Zig 0.16, NixOS 26.05), postgres 18 / mongo 8, lockfiles built from, non-root
runtimes, .dockerignore, per-project LICENSE, READMEs with the git.devai.io clone
line, checkout@v7 CI. Security fixes in the legacy Rust APIs (any-password login,
self-assigned admin, hard-coded JWT secret), JWT alg/exp/sub enforcement across the
blog series, safe markdown links in the frontends, and many smaller bugs — every
project was built, run and exercised end to end.

Adds scripts/publish.sh + a CI publish job that splits every folder into its own
repo at git.devai.io/templates/<folder>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01128fhuZbgivaSJvtMf4s1G
2026-09-27 21:10:38 +02:00

1.8 KiB

tip-calculator

A working tip calculator in one HTML file, one CSS file and about 30 lines of JavaScript. Type a bill, drag the tip slider, split it between friends — and learn the pattern behind almost every web page: read the inputs, do the math, write the answer back.

Run

Get it: git clone https://git.devai.io/templates/tip-calculator.git

Double-click index.html — it opens in your browser and works. Nothing to install, no build step.

Or serve it like production:

docker compose up --build

Then open http://localhost:8080.

How it works

The whole app is one function, calculate(): it reads the three inputs, works out the tip and the per-person total, and writes both back onto the page. One line makes it live:

el.addEventListener("input", calculate);

"Whenever this input changes, run calculate." Everything else is plain JavaScript: getElementById finds an element, parseFloat turns typed text into a number, and the built-in Intl.NumberFormat turns 19.5 into $19.50.

Try it: swap "USD" for "EUR" (and "en-US" for "de-DE"), add a "round up" checkbox, or raise the slider's max="30" for generous tippers.

Layout

index.html   the inputs — each has an id so JavaScript can find it
app.js       calculate() and the listeners that run it
styles.css   the look; follows your system's light or dark mode

Deploy

Push to your own GitHub repo and the shipped workflow (.github/workflows/ci.yml) tests the compose stack, publishes the image to GHCR, and — once you set the DEPLOY_HOST / DEPLOY_USER variables and DEPLOY_KEY secret — deploys it to your server over ssh.


Part of devai.io — the Web Basics track: HTML, CSS & JavaScript, one concept at a time. Next up: todo-list.