Search⌘ K
AI Features

Build the Functionality

Explore building essential functionalities of a budget tracker by coding the addIncome and addExpense functions in JavaScript. Understand program structure, use arrays and objects for data storage, and create an interactive loop for user input. Learn to scaffold remaining functions with AI assistance and test your code to ensure a working app.

In the previous lesson, you:

  • Chatted with a simulated client and gathered needs.

  • Converted notes into functional requirements.

  • Created a clean skeleton of eight function stubs.

Next, we’ll code the two core functions, scaffold the rest with AI, and add tests plus a reference solution.

We’ll keep a tiny in-memory data model:

// Monthly income (one number we can update)
let income = 0.0;
// A growing list of expenses
// Each entry: { category: string, amount: number }
let expenses = [];
// Allowed categories for expense logging
const allowedCategories = [
"Food", "Rent", "Transport", "Entertainment",
"Utilities", "Health", "Education", "Other"
];

We’ll use the following conventions:

  • Use positive amounts only.

  • Use arrays and objects (no external libraries or file I/O).

  • Keep functions small and reusable.

Build the basics

We’ll implement addIncome and addExpense first. These are the heartbeat of the app; everything else plugs into them.

addIncome(amount)

Before we start coding our first function, let’s take a look at how ...