Vibe Coding: build real apps with AI · Episode 11. Every agent run below is real: Claude Code 2.1.319 (model claude-sonnet-5-5) in print mode (claude -p), on 7 November 2026, in /home/ravi/projects/expenses (a Git repository). The page was served with python3 -m http.server 8091 and tested in Chromium with Playwright, time zone Asia/Kolkata, with Playwright's fake clock for the midnight test. Our test machine's network blocks the cdnjs CDN, so for the chart screenshots that request was answered with the same Chart.js 4.4.1 build from npm. Compiler outputs are from the SyntaxPilot compiler (Node.js 24).
The problem
Salary day: a full account. The 20th: almost nothing, and no idea where it went. A notebook gives wrong totals and no picture. Ravi wants: note each expense, the month's total, a chart by category, and a file he can open in Excel.
One prompt
claude -p "Make an expense tracker web app in a single index.html (HTML, CSS and JavaScript together). A form to add
an expense: amount in rupees (paise allowed), category (Food, Rent, Travel, Shopping, Other), date (today by default)
and a note. Show a list of expenses, the total for the current month, and a pie chart of this month by category using
Chart.js. Save everything in localStorage. Add a button to export all expenses as a CSV file."
--allowedTools Read Write Edit Glob
Real result: index.html, 259 lines. From the reply:
I haven't opened it in a browser or tested it, so it's untested. ... The pie chart needs an internet connection to load Chart.js 4.4.1 from cdnjs. If that fails, the chart area shows a message ... Amounts are stored as whole paise, so totals don't pick up rounding errors. ... The file has a BOM so Excel reads ₹ text correctly. Notes starting with
=,+,-or@get a leading'so Excel doesn't run them as formulas.
Forms (a railway reservation slip)
| Reservation slip | HTML form |
|---|---|
| boxes to fill: name, age, date | <input> fields: type="number", "date", "text" |
| tick one class | <select>: a fixed list of options |
| hand it to the counter | the submit event: the code reads every box |
<form id="form" novalidate>
<label>Amount (₹)
<input id="amount" type="number" step="0.01" min="0.01" required>
</label>
<label>Category
<select id="category">
<option>Food</option><option>Rent</option> ...
</select>
</label>
<label>Date <input id="date" type="date" required></label>
<label>Note <input id="note" type="text" maxlength="200"></label>
<button type="submit">Add expense</button>
</form>
step="0.01" allows paise, min="0.01" means at least one paisa, required means not empty. novalidate switches off the browser's own checks so the app's code does all the checking.
Validation (a bank cashier checks the slip)
// Parse "123.45" -> 12345 paise; returns null if invalid.
function toPaise(str) {
var s = String(str).trim();
if (!/^\d+(\.\d{1,2})?$/.test(s)) return null;
var p = Math.round(parseFloat(s) * 100);
return p > 0 ? p : null;
}
The regular expression ^\d+(\.\d{1,2})?$ means: one or more digits, then optionally a point and one or two digits. Real results, typed into the real page:
amount "" → Enter a valid amount in rupees (up to 2 decimal places).
amount "0" → Enter a valid amount in rupees (up to 2 decimal places).
amount "-50" → Enter a valid amount in rupees (up to 2 decimal places).
amount "10.555" → Enter a valid amount in rupees (up to 2 decimal places).
amount "1e3" → Enter a valid amount in rupees (up to 2 decimal places).
amount "249.5" → (added)
no date → Pick a date.
Browser validation is for the user's comfort; a server must check again (Episode 14).
Money that adds up
The obvious way, rupees as decimals:
const amounts = [0.10, 0.20]; // ₹0.10 and ₹0.20
let total = 0;
for (const a of amounts) total += a;
console.log("Total:", total);
console.log("Is it 0.30?", total === 0.30);
Total: 0.30000000000000004
Is it 0.30? false
Why: computers store numbers in binary (base 2). Some decimals, like 0.1, can't be written exactly in binary, just as ⅓ is 0.333… forever in decimal. This is floating-point error.
The fix: count whole paise.
const paise = [10, 20]; // ₹0.10 and ₹0.20 in paise
let total = 0;
for (const p of paise) total += p;
console.log("Total paise:", total);
console.log("Total: ₹" + (total / 100).toFixed(2));
Total paise: 30
Total: ₹0.30
Rule: store paise (integers), divide by 100 only to show.
Category totals
var now = new Date();
var prefix = now.getFullYear() + '-' + pad(now.getMonth() + 1); // "2026-11"
var totals = {}; CATS.forEach(function (c) { totals[c] = 0; });
var sum = 0;
expenses.forEach(function (e) {
if (e.date.slice(0, 7) === prefix) { // same month?
totals[e.category] = (totals[e.category] || 0) + e.paise;
sum += e.paise;
}
});
$('monthTotal').textContent = fmt(sum);
Hand check of the real November data: 12,000 + 249.50 + 0.10 + 0.20 + 1,180 + 2,399 = ₹15,828.80, which matches the page.
Chart.js (a tiffin service)
A library is code someone else wrote and tested that you add to your app. The chart.js npm package describes itself as "Simple HTML5 charts using the canvas element" (MIT licence). A CDN (content delivery network) is many servers around the world that deliver a file from one near you.
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js"></script>
...
chart = new Chart(canvas, {
type: 'pie',
data: { labels: labels, datasets: [{ data: data, backgroundColor: colors }] }
});
Versions: the AI chose 4.4.1; npm view chart.js version on 7 Nov 2026 printed 4.6.1. AI-picked versions come from memory and can be old.
When the CDN is blocked (as on our test machine), the AI's fallback shows: Chart unavailable (Chart.js failed to load). The total still works.
Run 2: six-month bar chart
claude -p "Add a bar chart below the pie chart that shows the total spent in each of the last 6 months, including the
current month, oldest on the left. Use Chart.js like the pie chart. Change only what is needed." --allowedTools Read Edit
+ function drawBar(now) {
+ if (typeof Chart === 'undefined') return;
+ for (var i = 5; i >= 0; i--) {
+ var d = new Date(now.getFullYear(), now.getMonth() - i, 1);
+ keys.push(d.getFullYear() + '-' + pad(d.getMonth() + 1));
Using day 1 avoids the month-skip trap (going back a month from the 31st can land in the wrong month). The agent noted: "If Chart.js fails to load, the bar chart is skipped without an error message."
Dates and time zones
UTC is the world's reference clock; India (IST) is UTC+05:30. A time zone turns one moment into a local date. 12:30 am on 1 November in India is still 31 October in London.
// 12:30 am in India on 1 November 2026
const paidAt = new Date("2026-11-01T00:30:00+05:30");
console.log(paidAt.toISOString());
console.log(paidAt.toISOString().slice(0, 10));
2026-10-31T19:00:00.000Z
2026-10-31
toISOString() always gives UTC. The AI built "today" from local parts instead (good):
function today() {
var d = new Date();
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
}
...
$('date').value = today(); // runs ONCE, when the page loads
The AI's real bug: an expense in the wrong month
30 Nov 23:50 add "Late dinner" ₹180 → date 2026-11-30 ✓
1 Dec 00:20 add "Auto home after midnight" ₹250, no reload
date box still says: 2026-11-30
saved as: 2026-11-30 ✗
This month: December 2026 ₹0.00 ✗
Cause: the default date was set once at page load; the tab stayed open past midnight.
claude -p "Bug in the monthly total: I left the page open at night. At 11:50 pm on 30 November I added "Late dinner"
(Rs 180). At 12:20 am on 1 December, without reloading, I added "Auto home after midnight" (Rs 250). It was saved with
the date 2026-11-30, and the December total shows Rs 0.00 even after a reload. The date box still said 30 November.
Find the cause and fix it. If I pick a date myself, keep my date. Change only what is needed." --allowedTools Read Edit
$('form').addEventListener('submit', function (ev) {
var paise = toPaise($('amount').value);
+ if (!datePicked) $('date').value = today(); // page may have been open across midnight
var date = $('date').value;
...
+ var datePicked = false; // true once the user chooses a date themselves
+ $('date').addEventListener('input', function () { datePicked = true; });
The agent also said: "the Rs 250 'Auto home after midnight' entry is still dated 2026-11-30. I didn't touch stored data." Fixing code does not fix data already saved.
Re-test (real):
1 Dec 00:20 saved as: 2026-12-01 ✓
This month: December 2026 ₹250.00 ✓
28 Nov picked by hand, then added → saved as 2026-11-28 ✓
CSV export
CSV (comma-separated values) is a table as plain text: one row per line, commas between columns. Text with a comma goes inside double quotes; a quote inside quotes is doubled. Real export of three tricky notes:
Date,Category,Amount (INR),Note
"2026-11-03","Food",249.50,"Thali, with Neha"
"2026-11-04","Other",500.00,"'=1+1"
"2026-11-05","Food",120.00,"Chai ""special"""
CSV formula injection: a cell starting with = (or +, -, @) can be run as a formula by a spreadsheet; the leading ' keeps it as text. The BOM (byte order mark) is an invisible first character that tells Excel the file is UTF-8, so ₹ shows correctly.
9cfc10b Refresh the default date at submit
08afd01 Bar chart: last 6 months
edd9ecb Expense tracker v1 (AI)
451aa62 Empty project
Common mistakes (real)
| Mistake | What you see | Why | Fix |
|---|---|---|---|
| Adding rupees as decimals | 0.30000000000000004 |
binary can't store 0.1 exactly | store whole paise; divide only to show |
toISOString().slice(0, 10) |
1 Nov 12:30 am IST → "2026-10-31" |
it gives UTC | build the date from local parts |
| Default date set once at load | December total ₹0.00 | tab open past midnight | refresh the default at submit |
| A library from a CDN | Chart unavailable (Chart.js failed to load). |
no network, no library | a fallback message, or serve the file yourself |
Mini project
Add a monthly budget (for example ₹15,000) that shows "₹X left" and turns red when over. One prompt per change. Test: the exact budget amount, one paisa over, a payment just after midnight on the 1st, and a reload.
What a good outcome looks like
The budget is stored in paise; "left" is computed from the same month total; exactly ₹15,000.00 spent shows ₹0.00 left (not red), ₹15,000.01 shows red; the midnight payment counts in the new month.
Practice questions
- Why store ₹249.50 as
24950?
Answer
Integers are exact; decimal rupees can pick up floating-point errors when added.
- What does
"2026-11-07".slice(0, 7)give, and why is it useful here?
Answer
"2026-11": the year and month, used to check whether an expense is in the current month.
- Why is
new Date().toISOString().slice(0,10)wrong for "today" in India just after midnight?
Answer
It's UTC, 5 hours 30 minutes behind IST, so between 00:00 and 05:30 IST it gives yesterday's date.
- How should a CSV cell containing
Thali, with Nehabe written?
Answer
"Thali, with Neha": inside double quotes so the comma stays in the cell.
- The AI wrote Chart.js 4.4.1. How do you check the current version?
Answer
npm view chart.js version (4.6.1 on 7 Nov 2026), or the library's own docs/releases.
Quiz
const a = 0.10, b = 0.20;
const pa = 10, pb = 20;
// A: console.log(a + b)
// B: console.log((pa + pb) / 100)
// C: console.log(a + b === 0.30)
// D: console.log(String(a) + String(b))
Which line prints exactly 0.3?
Answer
B. A prints 0.30000000000000004, C prints false, D prints "0.10.2".
Interview questions
- Why should money never be stored as a floating-point number? What do payment systems use instead?
- What is UTC, and how would you store and display dates for users in different time zones?
- What is CSV formula injection and how do you prevent it?
- What are the risks of loading a library from a public CDN?
- Client-side vs server-side validation: why do you need both?
Glossary
| Term | Meaning (plain words) | Example |
|---|---|---|
| Form | boxes a user fills in, then sends at once | the Add expense form |
<input> type |
what kind of box: number, date, text | type="date" |
<select> |
a dropdown with a fixed list | categories |
<label> |
the words for a box; clicking it focuses the box | "Amount (₹)" |
| Submit event | the moment the form is sent | addEventListener('submit', ...) |
| Validation | checking input before using it | reject -50 |
| Regular expression (regex) | a pattern text must match | ^\d+(\.\d{1,2})?$ |
novalidate |
turns off the browser's own form checks | <form novalidate> |
| Paise | 1/100 of a rupee; store money as whole paise | ₹249.50 = 24950 |
| Integer | a whole number | 24950 |
| Floating point | how computers store decimals, with tiny errors | 0.1 + 0.2 |
| Binary | base 2: numbers written with 0 and 1 | 0.1 can't be exact |
toFixed(2) |
show a number with 2 decimal places | 0.3.toFixed(2) → "0.30" |
| Category | a group an expense belongs to | Food, Rent |
| Total | the sum of amounts in a group | ₹15,828.80 |
| Library | ready, tested code you add to your app | Chart.js |
| Chart.js | a free JavaScript chart library | pie, bar |
| Canvas | an HTML element you can draw on | <canvas id="chart"> |
| CDN | servers worldwide that deliver files from near you | cdnjs |
| Version | a numbered release of a library | 4.4.1 vs 4.6.1 |
| npm view | prints a package's latest version | npm view chart.js version |
| UTC | the world's reference clock | ...Z in 2026-10-31T19:00:00.000Z |
| Time zone | the rule that turns a moment into a local time | IST = UTC+05:30 |
| ISO date | year-month-day text that sorts correctly | 2026-11-07 |
toISOString() |
a Date as UTC text | gives yesterday after midnight IST |
| Fake clock | a test tool that sets the browser's time | page.clock |
| Stale default | a default value that has gone out of date | the date box after midnight |
| CSV | a table as plain text with commas | expenses-2026-11-07.csv |
| BOM | an invisible first character marking UTF-8 | helps Excel show ₹ |
| CSV formula injection | a cell starting = run as a formula |
'=1+1 guard |
| Bug report prompt | exact steps, what you saw, what you expected | the midnight prompt |
Summary
A detailed prompt gave a careful first version: validation, money in paise, local dates, a CDN fallback, a safe CSV. We checked each claim: bad inputs rejected, a total verified by hand, 0.1 + 0.2 shown failing, toISOString shown giving yesterday. Testing past midnight with a fake clock found the AI's real bug: a stale default date that put a December expense in November. One precise prompt fixed it, and a re-test proved it.