Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions finance-tracker/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// This is the entrypoint for your application.
// node app.js
const { transactions } = require('./data');
const {
getTotalIncome,
getTotalExpenses,
getBalance
} = require('./finance');

console.log('PERSONAL FINANCE TRACKER');

const income = getTotalIncome(transactions);
const expenses = getTotalExpenses(transactions);
const balance = getBalance(transactions);

console.log('Total Income:', income);
console.log('Total Expenses:', expenses);
console.log('Current Balance:', balance);
48 changes: 46 additions & 2 deletions finance-tracker/data.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
// Place here the transaction data array. Use it in your application as needed.
const transactions = [];
const transactions = [
{
id: 1,
type: 'income',
category: 'salary',
amount: 3000,
description: 'Salary',
date: '2026-02-01'
},
{
id: 2,
type: 'expense',
category: 'housing',
amount: 1200,
description: 'Rent',
date: '2026-02-02'
},
{
id: 3,
type: 'expense',
category: 'food',
amount: 300,
description: 'Groceries',
date: '2026-02-03'
},
{
id: 4,
type: 'income',
category: 'side-income',
amount: 500,
description: 'Freelance',
date: '2026-02-04'
},
{
id: 5,
type: 'expense',
category: 'bills',
amount: 150,
description: 'Utilities',
date: '2026-02-05'
}
];

module.exports = {
transactions
};
42 changes: 24 additions & 18 deletions finance-tracker/finance.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
function addTransaction(transaction) {
// TODO: Implement this function
}
function getTotalIncome(transactions) {
let total = 0;

function getTotalIncome() {
// TODO: Implement this function
}
for (const transaction of transactions) {
if (transaction.type === 'income') {
total += transaction.amount;
}
}

function getTotalExpenses() {
// TODO: Implement this function
return total;
}

function getBalance() {
// TODO: Implement this function
}
function getTotalExpenses(transactions) {
let total = 0;

for (const transaction of transactions) {
if (transaction.type === 'expense') {
total += transaction.amount;
}
}

function getTransactionsByCategory(category) {
// TODO: Implement this function
return total;
}

function getLargestExpense() {
// TODO: Implement this function
function getBalance(transactions) {
return getTotalIncome(transactions) - getTotalExpenses(transactions);
}

function printAllTransactions() {
// TODO: Implement this function
}
module.exports = {
getTotalIncome,
getTotalExpenses,
getBalance
};