How a real app gets planned
Requirements → data → modules → UI states → edge cases → tests → shipping. And what a portfolio project should show.
1. Requirements. Words first, no code: what does the app do?
- type a city — see the temperature, the sky and the wind;
- while we wait for the server, you can see it's loading, and the button can't be pressed twice;
- city not found, server down, no network — a clear message, not a blank screen;
- the last five cities are remembered and survive a page reload.
Each item will become a test later. If a requirement can't be checked, it isn't thought through yet.
2. Data. Find out what the server answers *before* writing the interface. Our training API: GET /api/weather?city=Oslo → { "city": "Oslo", "temp": 6.6, "sky": "rain", "wind": 4 }; an unknown city is a 404. The temperature arrives as a fraction: rounding it and adding the + sign is our job.
3. Modules. Split the app into files by responsibility:
api.js— the network and its errors;format.js— pure functions: a number →"+7°";storage.js— localStorage;ui.js— the DOM: show a state;main.js— the entry point: wires everything together and listens to the form.
Why exactly like this is the topic of the next lesson.
4. UI states. At any moment the weather screen is in exactly one of four states: idle (nothing searched yet), loading, error, success. Describe them as objects, and rendering becomes one function: "state → screen".
function describe(state) {
switch (state.status) {
case "idle": return "Enter a city";
case "loading": return `Looking up: ${state.city}…`;
case "error": return `Error: ${state.message}`;
case "success": return `${state.data.city}: ${Math.round(state.data.temp)}°`;
}
}
console.log(describe({ status: "idle" }));
console.log(describe({ status: "loading", city: "Oslo" }));
console.log(describe({ status: "error", message: "City not found" }));
console.log(describe({ status: "success", data: { city: "Oslo", temp: 6.6 } }));5. Edge cases. This is where projects usually break: empty input and spaces, a city with a space or & in its name (you need encodeURIComponent), 404 and 500 (remember: fetch doesn't throw on those by itself — check res.ok), a dropped connection, a double click, corrupted JSON in localStorage, two quick searches in a row.
async function load(city) {
console.log("loading:", city);
try {
const res = await fetch(`/api/weather?city=${encodeURIComponent(city)}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log("success:", data.city, data.temp);
} catch (error) {
console.log("error:", error.message);
}
}
await load("Oslo");
await load("Atlantis");res.ok check, "Atlantis" would quietly turn into undefined.6. Tests. Pure functions (formatTemp, addRecent) are checked in a millisecond. Rendering is checked the way this course does it: pass in a state, read the DOM. The network is replaced with a fake server, like our api.
const formatTemp = (c) => (Math.round(c) > 0 ? `+${Math.round(c)}°` : `${Math.round(c)}°`);
function check(name, actual, expected) {
console.log(actual === expected ? "✓" : "✗", name, "→", actual);
}
check("warm", formatTemp(6.6), "+7°");
check("frost", formatTemp(-3.4), "-3°");
check("almost zero", formatTemp(-0.4), "0°");-0.4 rounds to -0, and ${-0} is "0". Lucky — but worth checking.7. Shipping. A bundler (Vite, for example) glues the modules into one file — the same thing our sandbox does with your tabs. The finished folder goes onto static hosting: GitHub Pages, Netlify, Vercel — and the project gets a link. The final touch is a README: what it is, a screenshot, how to run it, which decisions were made and why.
What to show in a portfolio. "It works" isn't enough for an employer. Show: a live link; a README that explains your decisions; all four states, errors included; tests; a tidy commit history; code split into modules. A small app that's actually finished is worth more than a big half-done one.
And if an AI writes the code? An assistant types faster than any cat, but the responsibility stays with you:
- specify the task like the requirements above: data, states, edge cases — a vague request gets vague code;
- read every line: if you can't explain what it does, don't commit it;
- check it with tests and by hand: empty input,
404, offline, a double click. AI confidently writes code that only works in the "sunny day" scenario.
Pop quiz
Mistakes are fine: keep trying until you find the right answer, and Byte explains why it's right.