CodingNeed.

2 · Model and build · 20 MIN

Project · Typed expense summary

Combine loops, objects, conditions, and functions.

Model each expense with a type, then combine filtering and summation. Compile-time types document trusted inputs. External input still needs runtime validation.

A budget sheet totals just the rows you are interested in.

Read the example

type Expense = {category:string; amount:number};
const expense: Expense = {category:"food", amount:5};
console.log(expense.amount);
Check the expected output
5

Your challenge

Input is {expenses: [{category, amount}], category}. Return the total amount for expenses whose category matches input.category. Do not mutate input.

Common trap

Adding every amount ignores the requested category.

Essential cookies keep your account signed in. Optional analytics is not configured on this site. Your choice does not affect access to lessons.

Read the Privacy Policy. You can change this choice in the footer.