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
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2
}
40 changes: 38 additions & 2 deletions finance-tracker/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
// This is the entrypoint for your application.
// node app.js
const chalk = require('chalk');
const transactions = require('./data');

const {
getTotalIncome,
getTotalExpenses,
getBalance,
getLargestExpense,
printAllTransactions,
} = require('./finance');

// Header
console.log(chalk.bold('\n💰 PERSONAL FINANCE TRACKER 💰'));

// All Transactions
console.log('\nAll Transactions:');
printAllTransactions();

// Summary Header
console.log(chalk.bold('\n📊 FINANCIAL SUMMARY 📊'));

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

console.log(`Total Income: ${chalk.green('€' + income)}`);
console.log(`Total Expenses: ${chalk.red('€' + expenses)}`);

// Balance color logic
const balanceColor = balance >= 0 ? chalk.cyan : chalk.red;
console.log(`Current Balance: ${balanceColor('€' + balance)}`);

// largest expenses and total
const largest = getLargestExpense();
console.log(
`\nLargerst Expenses: ${chalk.yellow(largest.description)} (${chalk.red('€' + largest.amount)})`,
);

console.log(`Total Transactions: ${transactions.length}\n`);
46 changes: 44 additions & 2 deletions finance-tracker/data.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
// 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: 'Monthly salary',
date: '2025-01-15',
},
{
id: 2,
type: 'expense',
category: 'housing',
amount: 1200,
description: 'Rent',
date: '2025-01-16',
},
{
id: 3,
type: 'expense',
category: 'food',
amount: 300,
description: 'Groceries',
date: '2025-01-17',
},
{
id: 4,
type: 'income',
category: 'side-income',
amount: 500,
description: 'Freelance',
date: '2025-01-18',
},
{
id: 5,
type: 'expense',
category: 'bills',
amount: 150,
description: 'Utilities',
date: '2025-01-19',
},
];

module.exports = transactions;
48 changes: 40 additions & 8 deletions finance-tracker/finance.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
const transactions = require('./data');

function addTransaction(transaction) {
// TODO: Implement this function
return [...transactions, transaction];
}

function getTotalIncome() {
// TODO: Implement this function
const total = transactions.reduce(
(total, tx) => (tx.type === 'income' ? total + tx.amount : total),
0,
);

return total;
}

function getTotalExpenses() {
// TODO: Implement this function
const total = transactions.reduce(
(total, tx) => (tx.type === 'expense' ? total + tx.amount : total),
0,
);
return total;
}

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

function getTransactionsByCategory(category) {
// TODO: Implement this function
const getByCatagory = transactions.filter((tx) => tx.category === category);
return getByCatagory;
}

function getLargestExpense() {
// TODO: Implement this function
const largest = transactions
.filter((tx) => tx.type === 'expense')
.reduce(
(max, tx) => (max === null || tx.amount > max.amount ? tx : max),
null,
);
return largest;
}

function printAllTransactions() {
// TODO: Implement this function
}
transactions.forEach((tx, index) => {
console.log(
`${index + 1}. [${tx.type.toUpperCase()}] ${tx.description} - €${tx.amount} (${tx.category})`,
);
});
}

module.exports = {
addTransaction,
getTotalIncome,
getTotalExpenses,
getBalance,
getTransactionsByCategory,
getLargestExpense,
printAllTransactions,
};
105 changes: 105 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "c55-core-week-4",
"version": "1.0.0",
"description": "The week 4 assignment for the HackYourFuture Core program can be found at the following link: https://hub.hackyourfuture.nl/core-program-week-4-assignment",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Dagim02/c55-core-week-4.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"bugs": {
"url": "https://github.com/Dagim02/c55-core-week-4/issues"
},
"homepage": "https://github.com/Dagim02/c55-core-week-4#readme",
"dependencies": {
"chalk": "^4.1.2"
},
"devDependencies": {
"prettier": "^3.8.1"
}
}