Ubc Cost Calculator

The user wants a complete, single-file HTML calculator and SEO article for “UBC Cost Calculator”.
I need to follow the strict rules provided:
1. **Output**: One complete HTML file.
2. **Tech Stack**: HTML, CSS (embedded), JS (embedded). No external libraries.
3. **JS Compatibility**: Use `var` only. No `const`, `let`, arrow functions, template literals.
4. **Layout**: Single-column, max-width 960-1100px.
5. **Visual Style**: Professional, #004a99 primary, #28a745 success, #f8f9fa background.
6. **Calculator Logic**:
* Topic: UBC Cost Calculator (University of British Columbia costs).
* Inputs: Tuition, Housing, Food, Books, Misc, Years of study, Scholarship/Financial Aid.
* Outputs: Total Cost, Annual Cost, Monthly Cost breakdown.
* Real-time updates.
* Reset button.
* Copy Results button.
* Table: Cost breakdown.
* Chart: Canvas or SVG (I’ll use Canvas for a bar chart).
7. **SEO Article**:
* Topic: UBC Cost Calculator.
* Sections: Definition, Formula, Examples, How to use, Factors, FAQ, Related Tools.
* Keywords: “UBC Cost Calculator”, “Cost of UBC”, “UBC Tuition”, etc.
* Internal Links: I will simulate these as they are placeholders in the prompt structure, but I need to generate realistic-looking anchor texts and hrefs based on the context.
* Keyword Density: >= 4% for “UBC Cost Calculator”.
* H1, Meta Description, Title.

**Plan:**

1. **HTML Structure**:
* ``
* ``: Meta tags, Title, Style.
* ``:
* Header (Title).
* Main Container.
* Calculator Section (Inputs, Canvas, Table, Results).
* Article Section (H2s, P, UL, Table).
* Footer.

2. **CSS**:
* Reset.
* Typography (sans-serif).
* Container centering.
* Input styling (padding, border, focus).
* Button styling (primary, success).
* Table styling (scrollable).
* Chart container (responsive).

3. **JavaScript**:
* Variables for DOM elements.
* `calculate()` function:
* Get values.
* Validate (check for negative numbers).
* Calculate: Tuition * Years + Housing * Years + Food * Years + Books * Years + Misc * Years – Aid.
* Update DOM elements.
* Update Chart data.
* `drawChart()` function: Canvas drawing logic using `ctx`.
* `reset()` function.
* `copyResults()` function.
* Event listeners on inputs (`oninput` or `addEventListener` – wait, rule says “Use inline onclick events” for buttons, but for inputs, real-time updates usually imply event listeners. I will use `oninput` in HTML tags to strictly follow “inline” vibe where possible, or standard `addEventListener` if cleaner, but the prompt says “Use inline onclick events” specifically in rule 6. I will stick to `oninput=”calculate()”` for inputs to be safe and explicit).

4. **Content Generation**:
* **Title**: UBC Cost Calculator: Estimate Your University of British Columbia Expenses
* **Meta**: Use this calculator to estimate tuition, housing, and living costs for UBC. Plan your budget for studying at the University of British Columbia.
* **Article**:
* *What is a UBC Cost Calculator?* Definition, who uses it.
* *Formula*: Breakdown of variables (Tuition, Housing, etc.).
* *Examples*: Domestic vs International student scenarios.
* *How to use*: Step-by-step.
* *Factors*: Inflation, Location, Lifestyle, etc.
* *FAQ*: 8 questions.
* *Related Tools*: Links to tuition calculators, GPA calculators, etc.

5. **Refining the JS**:
* Need to handle the chart. A simple bar chart comparing “Total Cost” vs “Scholarships” or a breakdown of expenses. Let’s do a breakdown of expenses by category over the duration.
* Chart logic: Clear canvas, draw axes, draw bars based on calculated values.

6. **Keyword Density Check**:
* I need to ensure “UBC Cost Calculator” appears frequently but naturally.

Let’s write the code.

*Self-Correction during drafting*: The prompt asks for “Use inline onclick events” in rule 6. I will apply this to buttons. For inputs, `oninput` is the standard inline event for real-time calculation.

*Internal Links*: Since I don’t have actual URLs, I will use placeholders like `/tools/tuition-calculator` but make them look realistic.

*Chart*: Native Canvas. I’ll draw a simple bar chart showing the breakdown of the total cost.

*Inputs*:
1. Years of Study (1-6)
2. Tuition (Annual)
3. Residence/Housing (Annual)
4. Food/Meals (Annual)
5. Books & Supplies (Annual)
6. Personal/Misc (Annual)
7. One-time Fees (Orientation, etc.)

*Outputs*:
1. Total Estimated Cost
2. Average Annual Cost
3. Monthly Budget Estimate

Let’s assemble.

*CSS Colors*:
Primary: #004a99
Success: #28a745
Bg: #f8f9fa

*JS Logic*:
`var total = (tuition + housing + food + books + misc + oneTime) * years;` (Wait, one-time fees usually aren’t multiplied by years, or maybe they are per year? Let’s assume One-time fees are total, or per year. Let’s make it “Annual Fees” to keep it simple, or “One-time Fees” separate. Let’s stick to Annual recurring costs + One-time costs).
Actually, for a “UBC Cost Calculator”, usually people want to know the total for a degree.
Let’s define inputs:
– Duration (Years)
– Annual Tuition
– Annual Housing
– Annual Food
– Annual Transport
– Annual Books
– Annual Personal
– One-time Initiation Fees

Calculation:
`Recurring = (Tuition + Housing + Food + Transport + Books + Personal) * Years`
`Total = Recurring + OneTime`

Let’s refine the chart. A pie chart is hard in raw canvas without libraries. A bar chart is easier.
Series 1: Tuition, Series 2: Housing, Series 3: Living, Series 4: Other.

Let’s go.

*Checking constraints*:
– Single column? Yes.
– No markdown? Yes.
– `var` only? Yes.
– Inline events? Yes.

*Article Content*:
Needs to be long-form and SEO optimized.
Keywords: “UBC Cost Calculator”, “University of British Columbia tuition”, “UBC living costs”, “budget for UBC”.

Let’s write the HTML.






UBC Cost Calculator: Estimate University of British Columbia Expenses







*Specifics for JS Chart*:
Canvas context `ctx`.
`ctx.fillRect` for bars.
Labels using `ctx.fillText`.

*Specifics for Copy*:
`navigator.clipboard.writeText` (might need fallback, but modern browsers support it. If not, `execCommand`). I’ll try clipboard API, it’s standard enough now.

*Specifics for Validation*:
If input < 0, show error message in a span below input. Let's finalize the structure. **Article Outline**: H1: UBC Cost Calculator: Comprehensive Guide to University of British Columbia Expenses H2: What is a UBC Cost Calculator? H2: The UBC Cost Calculator Formula H2: Practical Examples of UBC Cost Calculations H2: How to Use This UBC Cost Calculator H2: Key Factors Affecting Your UBC Costs H2: Frequently Asked Questions (FAQ) H2: Related Tools and Resources Internal Links (simulated): - UBC Tuition Fees Guide - Vancouver Housing Market Report - Student Budget Planner - Student Loans Guide - Campus Housing Application - International Student Handbook Let's generate the code. *One detail*: "Use inline onclick events". I will use `