From b920d3daf6f2a59ab418fb9e5b43a75530e33c73 Mon Sep 17 00:00:00 2001 From: Mustafa Homsi Date: Wed, 4 Feb 2026 14:01:19 +0100 Subject: [PATCH] mustafa --- finance-tracker/app.js | 17 ++++++++++++-- finance-tracker/data.js | 48 ++++++++++++++++++++++++++++++++++++-- finance-tracker/finance.js | 42 +++++++++++++++++++-------------- 3 files changed, 85 insertions(+), 22 deletions(-) diff --git a/finance-tracker/app.js b/finance-tracker/app.js index 7cfcd07..4284802 100644 --- a/finance-tracker/app.js +++ b/finance-tracker/app.js @@ -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); \ No newline at end of file diff --git a/finance-tracker/data.js b/finance-tracker/data.js index d7863ff..f128355 100644 --- a/finance-tracker/data.js +++ b/finance-tracker/data.js @@ -1,2 +1,46 @@ -// Place here the transaction data array. Use it in your application as needed. -const transactions = []; \ No newline at end of file +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 +}; \ No newline at end of file diff --git a/finance-tracker/finance.js b/finance-tracker/finance.js index ac2118f..d27f314 100644 --- a/finance-tracker/finance.js +++ b/finance-tracker/finance.js @@ -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 -} \ No newline at end of file +module.exports = { + getTotalIncome, + getTotalExpenses, + getBalance +}; \ No newline at end of file