From f5b4769179fc6dcfd0d25bbb5bd13a8192bed5d8 Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Wed, 4 Feb 2026 15:43:11 +0100 Subject: [PATCH] chore: initial project setup and finance tracker implementation --- finance-tracker/.gitignore | 1 + finance-tracker/.prettierrc | 6 +++ finance-tracker/app.js | 6 +++ finance-tracker/data.js | 46 +++++++++++++++- finance-tracker/finance.js | 88 ++++++++++++++++++++++++++++++- finance-tracker/package-lock.json | 86 ++++++++++++++++++++++++++++++ finance-tracker/package.json | 16 ++++++ 7 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 finance-tracker/.gitignore create mode 100644 finance-tracker/.prettierrc create mode 100644 finance-tracker/package-lock.json create mode 100644 finance-tracker/package.json diff --git a/finance-tracker/.gitignore b/finance-tracker/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/finance-tracker/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/finance-tracker/.prettierrc b/finance-tracker/.prettierrc new file mode 100644 index 0000000..b398104 --- /dev/null +++ b/finance-tracker/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "singleQuote": true, + "trailingComma": "es5", + "printWidth": 80 +} \ No newline at end of file diff --git a/finance-tracker/app.js b/finance-tracker/app.js index 7cfcd07..0062a37 100644 --- a/finance-tracker/app.js +++ b/finance-tracker/app.js @@ -1,3 +1,9 @@ // This is the entrypoint for your application. // node app.js +const chalk = require('chalk'); +const finance = require('./finance'); +console.log(chalk.bold.cyan('\nšŸ’° PERSONAL FINANCE TRACKER šŸ’°')); + +finance.printAllTransactions(); +finance.printSummary(); diff --git a/finance-tracker/data.js b/finance-tracker/data.js index d7863ff..43fa1e7 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 = [ + // Array of transaction objects + { + 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-01', + }, + { + id: 3, + type: 'expense', + category: 'food', + amount: 300, + description: 'Groceries', + date: '2025-01-10', + }, + { + id: 4, + type: 'income', + category: 'side-income', + amount: 500, + description: 'Freelance work', + date: '2025-01-20', + }, + { + id: 5, + type: 'expense', + category: 'bills', + amount: 150, + description: 'Utilities', + date: '2025-01-18', + }, +]; + +module.exports = transactions; diff --git a/finance-tracker/finance.js b/finance-tracker/finance.js index ac2118f..58f2333 100644 --- a/finance-tracker/finance.js +++ b/finance-tracker/finance.js @@ -1,27 +1,113 @@ +const chalk = require("chalk"); +const transactions = require("./data.js"); + function addTransaction(transaction) { // TODO: Implement this function + transactions.push(transaction); } function getTotalIncome() { // TODO: Implement this function + let totalIncome = 0; + for (const transaction of transactions) { + if (transaction.type === 'income') { + totalIncome += transaction.amount; + } + } + return totalIncome; } function getTotalExpenses() { // TODO: Implement this function + let totalExpenses = 0; + for (let i=0; i largestExpense.amount) { + largestExpense = {amount, description}; + } + } + } + return largestExpense; } function printAllTransactions() { // TODO: Implement this function -} \ No newline at end of file + console.log(chalk.bold('\nAll Transactions:\n')); + for (let i=0; i= 0 ? chalk.cyan(`€${balance}`) : chalk.red(`€${balance}`); + + console.log(chalk.bold('Current Balance:'), balanceColor); + + console.log( + chalk.bold('Largest Expense:'), + `${largestExpense.description} (€${largestExpense.amount})` + ); + + console.log(chalk.bold('Total Transactions:'), transactions.length); +} + +module.exports = { + addTransaction, + getTotalIncome, + getTotalExpenses, + getBalance, + getTransactionsByCategory, + getLargestExpense, + printAllTransactions, + printSummary, +}; \ No newline at end of file diff --git a/finance-tracker/package-lock.json b/finance-tracker/package-lock.json new file mode 100644 index 0000000..53a3231 --- /dev/null +++ b/finance-tracker/package-lock.json @@ -0,0 +1,86 @@ +{ + "name": "finance-tracker", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "finance-tracker", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "chalk": "^4.1.2" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "license": "MIT" + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + } + } +} diff --git a/finance-tracker/package.json b/finance-tracker/package.json new file mode 100644 index 0000000..a957a93 --- /dev/null +++ b/finance-tracker/package.json @@ -0,0 +1,16 @@ +{ + "name": "finance-tracker", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "dependencies": { + "chalk": "^4.1.2" + } +}