Disclosure: I used an AI assistant to help draft and edit this post. The code was written for the post and checked by hand.
When you build a calculator, the math is the easy part. After launch, the requests that come in are rarely about the formula. They are things like "can I save my results?" and "can I print this?". Both are cheap to add if you plan for them, and both make a tool feel finished.
I work on small score calculators for fitness tests, where people want to keep a record of practice results from week to week. These are the two features that came up first, and how I built them without a library.
Start with one results object
Both features get easy when the result of a calculation is a plain object instead of text pushed straight into the page. Something like this:
function buildResult(inputs, scores) { return { date: new Date().toISOString().slice(0, 10), age: inputs.age, sex: inputs.sex, events: scores.map(s => ({ name: s.name, raw: s.raw, points: s.points })), total: scores.reduce((sum, s) => sum + s.points, 0) }; } The page renders from this object, the CSV export reads from it, and the print view reads from it. One source of truth means the three can never disagree.
CSV export in about twenty lines
A CSV is just text with a few escaping rules. A field that contains a comma, a quote, or a line break must be wrapped in double quotes, and any quote inside it must be doubled.
function csvCell(value) { const s = String(value ?? ""); return /[",\n]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s; } function resultToCsv(result) { const rows = [["date", "event", "raw", "points"]]; for (const e of result.events) { rows.push([result.date, e.name, e.raw, e.points]); } rows.push([result.date, "TOTAL", "", result.total]); return rows.map(r => r.map(csvCell).join(",")).join("\r\n"); } function downloadCsv(result) { const blob = new Blob([resultToCsv(result)], { type: "text/csv;charset=utf-8" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "results-" + result.date + ".csv"; a.click(); URL.revokeObjectURL(url); } Two details are worth the extra line. First, use \r\n between rows, because that is what the CSV format specifies and spreadsheet programs handle it best. Second, if your values can start with =, +, - or @, a spreadsheet may treat them as formulas. A calculator that only exports numbers and fixed event names is safe, but if you ever export free text, prefix those cells with a single quote.
Time values deserve a thought too. If a run time is shown as 15:30, spreadsheets may reinterpret it as a clock time. Exporting the raw value in seconds in its own column, next to the display value, avoids confusing surprises.
A print view with only CSS
You do not need a separate page for printing. A @media print block can hide the form, the ads, and the navigation, and leave the result table.
@media print { header, nav, footer, form, .no-print { display: none !important; } body { font-size: 12pt; color: #000; background: #fff; } table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #000; padding: 4px 8px; } a[href]::after { content: " (" attr(href) ")"; font-size: 10pt; } } The last rule prints the URL after each link, which is handy on paper. If you do not want that for every link, scope it to a class.
Add a small button that calls window.print(), and test it in the browser's print preview. The most common problems I found were a dark background that wastes ink, table rows split across two pages, and a result that only existed inside a collapsed panel. A rule like tr { break-inside: avoid; } fixes the split rows.
Keep the buttons honest
Disable both buttons until there is a result to export. A download button that produces an empty file is worse than no button. Also announce the action to assistive technology, for example by updating a status region with "CSV downloaded", so people who cannot see the file save know it worked.
Test the boring parts
The escaping function is where bugs hide. A few cases cover it:
console.assert(csvCell("plain") === "plain"); console.assert(csvCell("a,b") === '"a,b"'); console.assert(csvCell('say "hi"') === '"say ""hi"""'); console.assert(csvCell(null) === ""); If those pass and a real file opens cleanly in a spreadsheet, you are most of the way there.
Wrapping up
None of this is glamorous, but these two features turn a one-time calculator into something people return to, because their numbers can leave the page. If you want to see a real example of a calculator that shows results by event, the one I work on is at https://aftptcalc.com/ and the same pattern applies to any scoring tool.
What small feature did users ask you for right after launch? I would be curious to hear it.

