This is your capstone! Bring together everything you've learned — variables, arrays, loops, conditionals, and functions — to build a working expense tracker in JavaScript.
YOUR TASK
Create a program that:
Stores expenses in an array (at least 3 values)
Has an addExpense(amount) function that pushes to the array
Has a getTotal() function that loops through the array and returns the sum
Has a showExpenses() function that logs each expense
Calls all three functions and logs the total
Use functions to keep everything clean and reusable.
Need a hint?
Structure to follow:
1. const expenses = [];
2. function addExpense(amount) {'{'} expenses.push(amount); {'}'}
3. Add expenses: addExpense(20); addExpense(30);
4. function getTotal() {'{'} let total = 0; for (let i = 0; i < expenses.length; i++) {'{'} total += expenses[i]; {'}'} return total; {'}'}
5. function showExpenses() {'{'} for (let i = 0; i < expenses.length; i++) {'{'} console.log("Expense: " + expenses[i]); {'}'} {'}'}
6. showExpenses();
7. console.log("Total: " + getTotal());
Example (expenses: 20, 30):
Expense: 20
Expense: 30
Total: 50
Code Editor
Ready
Output
Console
Console initialized...
Ready for Final Project: Expense Tracker
> Use "Check My Code" to test your tracker
> Once it passes, hit Complete Course!