Vibe Coding: build real apps with AI · Episode 8. 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/tip (a Git repository). The agent could read and write files but run no commands, so it never opened a browser; every page result below is the agent's real file opened in Chromium with the values shown typed in. Replies are quoted exactly, shortened where marked ....
The problem: who pays what?
Ravi, Neha and Sam eat out. Bill ₹1,000, plus a 10% tip: ₹1,100. On a phone calculator, 1100 ÷ 3 = 366.666... Three phones, three answers. Let's build a page: type three numbers, press a button, get the answer.
What a web page is made of (a house)
| A house | A web page | Job |
|---|---|---|
| walls, doors, rooms | HTML (HyperText Markup Language) | the content and structure: a heading, a box, a button |
| paint, tiles, curtains | CSS (Cascading Style Sheets) | how it looks: colours, sizes, layout |
| wiring and switches | JavaScript | what it does when you click |
All three can live in one file, index.html, the name web servers look for first:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tip Calculator</title>
<style> ... CSS: how it looks ... </style>
</head>
<body>
... HTML: what is on the page ...
<script> ... JavaScript: what it does ... </script>
</body>
</html>
Open it in any browser (Chrome, Edge, Firefox) and it runs. No installs.
One prompt
ravi@laptop:~/projects/tip$ claude -p "Make a tip calculator web page in a single file, index.html. Inputs: bill amount in rupees, tip percent, and number of people. A Calculate button shows the tip per person and the total per person." --allowedTools Read Write Edit
1 Write index.html (50 lines)
2 Reply: "I've created /home/ravi/projects/tip/index.html, a single file with
no dependencies. I haven't opened it in a browser or tested it.
- Inputs: bill amount in ₹, tip %, and number of people (defaults to 1).
- Calculate button: it shows the tip per person and the total per
person, formatted in rupees with Indian digit grouping.
- Validation: if a field is empty or invalid (for example, fewer than
1 person), it shows an error message instead of a result.
To try it, open the file in a browser."
Opened in Chrome: ₹1000, 10%, 3 people → Tip per person ₹33.33, Total per person ₹366.67. It works, first time. Now read it.
Inside: HTML elements, tags and attributes
<div class="card">
<h1>Tip Calculator</h1>
<label for="bill">Bill amount (₹)</label>
<input id="bill" type="number" min="0" step="0.01" placeholder="e.g. 1200">
<label for="tip">Tip (%)</label>
<input id="tip" type="number" min="0" step="0.1" placeholder="e.g. 10">
<label for="people">Number of people</label>
<input id="people" type="number" min="1" step="1" value="1">
<button id="calc">Calculate</button>
<div id="result" aria-live="polite"></div>
</div>
- An element is one thing on the page, written with tags in angle brackets:
<h1>Tip Calculator</h1>opens and closes. <label>is the text above a box;<input>is the box you type in (no closing tag);<button>is a button;<div>is a plain container.- Attributes are settings inside a tag:
type="number"(number box),min="0"(smallest value),placeholder(grey hint). idis a unique name, like a house number, so JavaScript can find that exact element:bill,tip,people,calc,result.
Inside: CSS rules
h1 { margin: 0 0 16px; font-size: 1.4rem; }
label { display: block; margin: 12px 0 4px; font-size: .9rem; color: #444; }
button { width: 100%; margin-top: 18px; padding: 12px; font-size: 1rem;
background: #2563eb; color: #fff; border: 0; border-radius: 6px; }
button:hover { background: #1d4ed8; }
.error { color: #b91c1c; }
- A selector picks elements:
h1(every h1),.error(every element with classerror),button:hover(a button while the mouse is over it). - Inside
{ }are properties and values:font-size: 1.4rem;,color: #b91c1c;. - A class is a group label many elements can share; an id is unique.
Inside: JavaScript and events (a doorbell)
| A doorbell | In the browser |
|---|---|
| someone rings, you didn't plan when | an event: a click, a key press, typing |
| you listen for it all day | addEventListener('click', ...) |
| you open the door, same steps each time | the function runs: read boxes, do maths, show |
const fmt = n => '₹' + n.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
document.getElementById('calc').addEventListener('click', () => {
const bill = parseFloat(document.getElementById('bill').value);
const tip = parseFloat(document.getElementById('tip').value);
const people = parseInt(document.getElementById('people').value, 10);
const out = document.getElementById('result');
if (!(bill >= 0) || !(tip >= 0) || !(people >= 1)) {
out.innerHTML = '<span class="error">Enter a valid bill, tip percent, and at least 1 person.</span>';
return;
}
const tipTotal = bill * tip / 100;
out.innerHTML =
'<div><span>Tip per person</span><strong>' + fmt(tipTotal / people) + '</strong></div>' +
'<div><span>Total per person</span><strong>' + fmt((bill + tipTotal) / people) + '</strong></div>';
});
- Line 2: find the button by id; when it's clicked, run the code in
{ }. - Lines 3-5:
.valueis what you typed. A box's value is always text (a string).parseFloatturns text into a number with decimals;parseIntinto a whole number. - Line 7: if anything is invalid, show the red error;
returnstops here. - Lines 11-14: the maths, then
innerHTMLputs the answer into the result box.fmtformats rupees with Indian commas (toLocaleString('en-IN')).
Bug 1: 2.5 people
Typed 2.5 people → ₹550.00 each, no error. ₹1,100 split by 2: a friend vanished from the bill.
console.log(parseInt("2.5"));
console.log(Number("2.5"));
console.log(Number.isInteger(Number("2.5")));
console.log(Number(""));
2
2.5
false
0
parseInt("2.5") reads digits until it hits something that isn't one and quietly stops. Number("2.5") gives the real value, and Number.isInteger says it isn't whole.
ravi@laptop:~/projects/tip$ claude -p "Bug: in index.html, when I type 2.5 in Number of people, it silently splits by 2 and shows Total per person ₹550.00. It should show an error instead: the number of people must be a whole number, 1 or more. Change only what's needed." --allowedTools Read Edit
- const people = parseInt(document.getElementById('people').value, 10);
+ const people = Number(document.getElementById('people').value);
...
- if (!(bill >= 0) || !(tip >= 0) || !(people >= 1)) {
- out.innerHTML = '<span class="error">Enter a valid bill, tip percent, and at least 1 person.</span>';
+ if (!(bill >= 0) || !(tip >= 0) ) {
+ out.innerHTML = '<span class="error">Enter a valid bill and tip percent.</span>';
+ return;
+ }
+ if (!Number.isInteger(people) || people < 1) {
+ out.innerHTML = '<span class="error">Number of people must be a whole number, 1 or more.</span>';
return;
Re-test: 2.5 → "Number of people must be a whole number, 1 or more."
Bug 2: money that doesn't add up
console.log(1100 / 3);
console.log(366.67 * 3);
366.6666666666667
1100.01
Three people paying ₹366.67 pay ₹1,100.01: one paisa too much. Do money in whole paise.
ravi@laptop:~/projects/tip$ claude -p "Next problem in index.html: bill ₹1000, tip 10%, 3 people shows Total per person ₹366.67. But 3 × 366.67 = ₹1100.01, one paisa more than the real total of ₹1100. Make the amounts add up exactly: if it doesn't divide evenly, show who pays the extra paise (for example: 2 people pay ₹366.67, 1 person pays ₹366.66). Do the maths in whole paise, not decimals." --allowedTools Read Edit
// All maths in whole paise (integers); tip % held in tenths of a percent.
const billPaise = Math.round(bill * 100);
const tipTenths = Math.round(tip * 10);
const tipPaise = Math.floor((2 * billPaise * tipTenths + 1000) / 2000); // round half up
const totalPaise = billPaise + tipPaise;
// Split paise across people: `extra` people pay one paisa more than the rest.
const split = (paise, label) => {
const base = Math.floor(paise / people);
const extra = paise % people;
...
Read the first comment: "tip % held in tenths of a percent". Test it:
| Test | Expected | The page | |
|---|---|---|---|
| ₹1000, 10%, 3 | 2 pay ₹366.67, 1 pays ₹366.66 (₹1,100.00) | same | pass |
| ₹1000, 12.75%, 1 | tip ₹127.50 | tip ₹128.00 | fail |
The AI's real mistake: it rounded the tip percent
Nobody asked for it: Math.round(tip * 10) turned 12.75% into 12.8%.
ravi@laptop:~/projects/tip$ claude -p "Bug in index.html: bill ₹1000, tip 12.75%, 1 person shows Tip per person ₹128.00. It should be ₹127.50. Don't round the tip percent; only round the final tip to the nearest paisa." --allowedTools Read Edit
"Cause: the tip percent was rounded to one decimal place (Math.round(tip * 10)),
so 12.75% became 12.8%. That gave ₹128.00 instead of ₹127.50."
+ const billPaise = BigInt(Math.round(bill * 100));
+ const tipScaled = BigInt(tip.toFixed(10).replace('.', '')); // percent * 1e10
+ const denom = 100n * 10n ** 10n;
+ const tipPaise = Number((2n * billPaise * tipScaled + denom) / (2n * denom)); // round half up
+ const billPaiseNum = Number(billPaise);
+ const totalPaise = billPaiseNum + tipPaise;
Correct (₹127.50), but BigInt (whole numbers of any size) and 10¹⁰ scaling are hard to explain. Episode 7's rule: never ship code you can't explain. So ask for simpler code:
ravi@laptop:~/projects/tip$ claude -p "The tip maths in index.html now uses BigInt and 1e10 scaling. That's too hard for me to explain. Make it simple enough for a beginner: Math.round(billPaise * tip / 100) for the tip in paise is fine. Keep everything else the same." --allowedTools Read Edit
+ // All maths in whole paise (integers); only the final tip is rounded.
+ const billPaise = Math.round(bill * 100);
+ const tipPaise = Math.round(billPaise * tip / 100);
+ const totalPaise = billPaise + tipPaise;
"... For some inputs, floating-point error could make the tip differ by
1 paisa from the old exact result. That's the usual cost of the simpler maths."
Re-test all earlier cases: 12.75% → ₹127.50, 2.5 people → error, 10% for 3 → adds up. All pass.
The paise split, run on its own
const billPaise = 100000;
const tipPaise = Math.round(billPaise * 10 / 100);
const totalPaise = billPaise + tipPaise;
const people = 3;
const base = Math.floor(totalPaise / people);
const extra = totalPaise % people;
console.log("total paise:", totalPaise);
console.log("base:", base, "extra:", extra);
console.log(extra, "people pay", (base + 1) / 100);
console.log(people - extra, "person pays", base / 100);
total paise: 110000
base: 36666 extra: 2
2 people pay 366.67
1 person pays 366.66
Math.floor rounds down; % gives the remainder. 2 × 366.67 + 366.66 = 1,100.00 exactly.
Changes: styling and the Enter key
ravi@laptop:~/projects/tip$ claude -p "Two small changes to index.html: make the Total per person amount big and green, and make pressing Enter in any input box do the same as clicking Calculate." --allowedTools Read Edit
+ #result .total strong { font-size: 2rem; color: #16a34a; }
...
- document.getElementById('calc').addEventListener('click', () => {
+ const calculate = () => {
...
+ document.getElementById('calc').addEventListener('click', calculate);
+ document.querySelectorAll('input').forEach(el =>
+ el.addEventListener('keydown', e => { if (e.key === 'Enter') calculate(); }));
One calculate function, two "doorbells" (a click and an Enter key press). On a 360px-wide phone screen, Enter pressed: big green ₹366.67*, with "2 people pay ₹366.67, 1 person pays ₹366.66 (adds up to ₹1,100.00)".
ravi@laptop:~/projects/tip$ git log --oneline
f9603f8 Big green total, Enter calculates
e05647b Simpler tip maths
188a8e1 Don't round tip percent (AI)
133e426 Split in whole paise (AI)
ec94cfc People must be a whole number
8e0e388 Tip calculator v1 (AI)
The final index.html (real)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tip Calculator</title>
<style>
body { font-family: system-ui, sans-serif; background: #f2f4f8; margin: 0; display: flex; justify-content: center; padding: 24px 16px; }
.card { background: #fff; width: 100%; max-width: 380px; padding: 24px; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.1); }
h1 { margin: 0 0 16px; font-size: 1.4rem; }
label { display: block; margin: 12px 0 4px; font-size: .9rem; color: #444; }
input { width: 100%; box-sizing: border-box; padding: 10px; font-size: 1rem; border: 1px solid #ccc; border-radius: 6px; }
button { width: 100%; margin-top: 18px; padding: 12px; font-size: 1rem; background: #2563eb; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
button:hover { background: #1d4ed8; }
#result { margin-top: 18px; font-size: 1.05rem; }
#result div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #eee; }
#result .split { display: block; font-size: .85rem; color: #555; }
#result .total strong { font-size: 2rem; color: #16a34a; }
#result .total { align-items: center; }
.error { color: #b91c1c; }
</style>
</head>
<body>
<div class="card">
<h1>Tip Calculator</h1>
<label for="bill">Bill amount (₹)</label>
<input id="bill" type="number" min="0" step="0.01" placeholder="e.g. 1200">
<label for="tip">Tip (%)</label>
<input id="tip" type="number" min="0" step="0.1" placeholder="e.g. 10">
<label for="people">Number of people</label>
<input id="people" type="number" min="1" step="1" value="1">
<button id="calc">Calculate</button>
<div id="result" aria-live="polite"></div>
</div>
<script>
const fmt = n => '₹' + n.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
const calculate = () => {
const bill = parseFloat(document.getElementById('bill').value);
const tip = parseFloat(document.getElementById('tip').value);
const people = Number(document.getElementById('people').value);
const out = document.getElementById('result');
if (!(bill >= 0) || !(tip >= 0) ) {
out.innerHTML = '<span class="error">Enter a valid bill and tip percent.</span>';
return;
}
if (!Number.isInteger(people) || people < 1) {
out.innerHTML = '<span class="error">Number of people must be a whole number, 1 or more.</span>';
return;
}
// All maths in whole paise (integers); only the final tip is rounded.
const billPaise = Math.round(bill * 100);
const tipPaise = Math.round(billPaise * tip / 100);
const totalPaise = billPaise + tipPaise;
// Split paise across people: `extra` people pay one paisa more than the rest.
const split = (paise, label) => {
const base = Math.floor(paise / people);
const extra = paise % people;
const cls = label === 'Total' ? ' class="total"' : '';
if (extra === 0) {
return '<div' + cls + '><span>' + label + ' per person</span><strong>' + fmt(base / 100) + '</strong></div>';
}
const plural = n => n + (n === 1 ? ' person pays ' : ' people pay ');
return '<div' + cls + '><span>' + label + ' per person</span><strong>' + fmt((base + 1) / 100) + '*</strong></div>' +
'<div class="split">* ' + plural(extra) + fmt((base + 1) / 100) + ', ' +
plural(people - extra) + fmt(base / 100) + ' (adds up to ' + fmt(paise / 100) + ')</div>';
};
out.innerHTML = split(tipPaise, 'Tip') + split(totalPaise, 'Total');
};
document.getElementById('calc').addEventListener('click', calculate);
document.querySelectorAll('input').forEach(el =>
el.addEventListener('keydown', e => { if (e.key === 'Enter') calculate(); }));
</script>
</body>
</html>
Your hand-test checklist
- A normal case: 1000, 10%, 3
- Empty boxes
- Odd numbers: 2.5 people, 0 people, -5
- Decimals: 12.75%, ₹999.99
- Does the money add up?
- Phone width, and the Enter key
After every fix, re-run the whole list.
Common mistakes (real)
| What happened | What you see | Why | Fix |
|---|---|---|---|
parseInt on "2.5" people |
₹550.00 each, no error | parseInt quietly drops the decimal |
Number() + Number.isInteger() |
| rounding each share | 3 × ₹366.67 = ₹1100.01 | decimal shares don't add up | whole paise: base + leftover paise |
| AI rounded the tip percent | 12.75% → ₹128.00 | "tip % held in tenths of a percent" | read comments; test decimals |
| a fix you can't explain | BigInt, 1e10 scaling |
correct but too clever | "make it simple enough for a beginner" |
Mini project
Build your own tip calculator (any AI tool), run the six-point checklist, and fix one bug with a one-change prompt. Stretch: add a "round up to the nearest ₹10" option.
What a good outcome looks like
A single index.html that opens in a browser, rejects 2.5 and 0 people with a clear message, shows amounts that add up exactly to the total, and a Git history with one commit per change. Your bug prompt should say what you typed, what you saw, and what should happen.
Practice questions
- What does each of HTML, CSS and JavaScript do?
Answer
HTML: content and structure. CSS: how it looks. JavaScript: what it does (behaviour).
- What's the difference between an attribute and an element?
Answer
An element is a thing on the page (<input>); an attribute is a setting inside its tag (type="number").
- What does
addEventListener('click', f)do?
Answer
It runs function f every time that element is clicked.
- Why does
parseInt("2.5")give 2?
Answer
It reads digits until it hits a character that isn't part of a whole number and stops, without an error.
- How do you split ₹1,100 between 3 people so it adds up?
Answer
In paise: 110000 ÷ 3 = 36666 remainder 2. Two people pay 36667 paise (₹366.67), one pays 36666 (₹366.66).
Quiz
// you typed 500 in the bill box
const a = bill.value;
console.log(a + 100);
A) 600 · B) 500100 · C) NaN · D) An error
Answer
B. A box's value is text; text + 100 joins them. Number(a) + 100 gives 600.
Interview questions
- What happens when you click a button on a web page? The browser fires a click event; any listener added with
addEventListenerruns its function, which can read inputs and update the page. - Why shouldn't you use floating-point numbers for money? Decimals like 0.1 can't be stored exactly and rounding each share loses or adds paise; use whole paise (integers) and hand out the remainder.
- How do you test a small UI you built with AI? A checklist: normal case, empty and invalid input, decimals and edge values, totals that must add up, phone width and keyboard use; re-run it after every change.
Glossary
| Term | Meaning (plain words) | Example |
|---|---|---|
| HTML | the language for a page's content and structure | <h1>Tip Calculator</h1> |
| CSS | the language for how a page looks | color: #b91c1c; |
| JavaScript | a programming language that runs in the browser | addEventListener(...) |
index.html |
the default page of a folder or website | the whole app |
| Browser | the app that opens web pages | Chrome, Edge, Firefox |
| Element | one thing on the page | <button> |
| Tag | the angle-bracket markers of an element | <h1> ... </h1> |
| Attribute | a setting inside a tag | type="number" |
id |
a unique name for one element | id="bill" |
| Class | a shared group label for styling | class="error" |
<input> |
a box you type in | <input id="tip"> |
<button> |
a clickable button | <button id="calc"> |
| Selector | the part of a CSS rule that picks elements | .error, button:hover |
| Property / value | what to change and to what | font-size: 2rem |
rem |
a size relative to the page's base font size | 1.4rem |
| Event | something the user does | click, keydown |
| Event listener | code that waits for an event | addEventListener('click', calculate) |
| String | text in code | "2.5" |
parseFloat / parseInt |
text → number with decimals / whole number | parseInt("2.5") → 2 |
Number() |
text → number, exactly | Number("2.5") → 2.5 |
Number.isInteger |
is it a whole number? | false for 2.5 |
innerHTML |
the HTML inside an element; setting it changes the page | the result box |
Math.round / Math.floor |
round to nearest / round down | Math.floor(36666.67) |
% (remainder) |
what's left after dividing | 110000 % 3 → 2 |
| Paise | 1/100 of a rupee; whole numbers for money | 36667 |
| BigInt | JavaScript whole numbers of any size | 10n ** 10n |
| Edge case | an unusual input that can break code | 2.5 people, 12.75% |
Summary
- HTML = structure, CSS = looks, JavaScript = behaviour; one
index.htmlruns in any browser. - Elements have tags and attributes; events like click run your code; a box's value is text.
- The AI said "I haven't tested it", so you test: 2.5 people, money that adds up, decimals.
- Read the AI's comments: "tip % held in tenths of a percent" was a real bug.
- Ask for one change at a time, and for simpler code when you can't explain it.
Next episode: Project: your portfolio website: responsive design, flexbox and grid, images and alt text, accessibility, and a Lighthouse score.