Build an interactive calculator with AI
Create a project estimate calculator with clear maths and a shareable link.
1. Define the calculation
Build a project cost estimator: hours × hourly rate + fixed costs, then add a contingency percentage. This is a budgeting example, not a recommended pricing strategy. Decide the formula before asking AI to design anything.
subtotal = hours × hourlyRate + fixedCosts total = subtotal × (1 + contingencyPercent / 100)
2. Build the first version
Paste this into your coding assistant:
Build a responsive project estimate calculator in one index.html with CSS and JavaScript. Use a light background and purple buttons (#8b2bbd; hover #681d91). Inputs: hours, hourly rate, fixed costs, contingency percent. Display subtotal, contingency amount and total to two decimals. Formula: subtotal = hours * rate + fixedCosts; total = subtotal * (1 + contingency / 100). Use SGD labels. Validate finite non-negative inputs; require hours and rate above zero, contingency 0–100. Treat blank required inputs as invalid, not zero. Show inline errors, accessible labels, keyboard focus and a polite result announcement on Calculate. Include Calculate and Reset buttons. Fit a 320px phone screen without horizontal scrolling. No external services, login, tracking or API keys. Explain how to open the file locally.
3. Test the maths
Open index.html in your browser. Enter 10 hours, rate 50, fixed costs 100 and contingency 10. Expect subtotal 600.00, contingency 60.00, total 660.00. With contingency 0, the total should be 600.00.
Try a blank hours field, a negative rate and contingency 101: each should show an error instead of a result. Check decimal hours (1.5 × 50 = 75), Reset, keyboard navigation and a narrow phone screen. Ask AI to fix any failing case, then rerun it.
4. Make the result explain itself
Show a breakdown below the result: hours × rate, fixed costs, contingency and total. Add “Estimate only; excludes taxes unless included in your inputs.” Keep the calculation deterministic in JavaScript. Add no AI calls. Preserve the validated formula and test cases.
Keep totals rounded for display, not at each intermediate calculation. Make labels understandable without hovering.
5. Share it
Create a public GitHub repository, upload index.html to the root and commit it. In Settings → Pages, choose Deploy from a branch, select your main branch and / (root), then save. Wait for deployment and open the site URL shown there. Run the 660.00 test again on the published page.
If you see a 404, confirm the file is named index.html, the selected branch contains it, and the Pages deployment succeeded. Only publish files intended to be public.