diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3cbc8b1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# .editorconfig +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2b76d7c..9395df8 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,6 @@ dist vite.config.js.timestamp-* vite.config.ts.timestamp-* +# node modules +node_modules/ + diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1c49d82 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +node_modules/ +package-lock.json +dist/ +build/ +*.min.js \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..85fd947 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "semi": true, + "trailingComma": "es5", + "singleQuote": true, + "printWidth": 80, + "tabWidth": 2, + "useTabs": false +} diff --git a/README.md b/README.md index 2de48c5..f0e2ccf 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ The week 4 assignment for the HackYourFuture Core program can be found at the fo - Implement the requirements in the `finance-tracker` folder. - Use the existing file structure. - You are allowed to create additional files if needed. +console.log asdsd \ No newline at end of file diff --git a/finance-tracker/app.js b/finance-tracker/app.js index 7cfcd07..8765df1 100644 --- a/finance-tracker/app.js +++ b/finance-tracker/app.js @@ -1,3 +1,5 @@ -// This is the entrypoint for your application. -// node app.js +const { printAllTransactions, printSummary } = require('./finance'); +printAllTransactions(); + +printSummary(); diff --git a/finance-tracker/data.js b/finance-tracker/data.js index d7863ff..2db6c82 100644 --- a/finance-tracker/data.js +++ b/finance-tracker/data.js @@ -1,2 +1,44 @@ -// 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: '2025-01-15', + }, + { + id: 2, + type: 'expense', + category: 'housing', + amount: 1200, + description: 'Rent', + date: '2025-01-20', + }, + { + id: 3, + type: 'expense', + category: 'food', + amount: 300, + description: 'Groceries', + date: '2025-01-22', + }, + { + id: 4, + type: 'income', + category: 'side-income', + amount: 500, + description: 'Freelance', + date: '2025-01-25', + }, + { + id: 5, + type: 'expense', + category: 'bills', + amount: 150, + description: 'Utilities', + date: '2025-01-28', + }, +]; + +module.exports = transactions; diff --git a/finance-tracker/finance.js b/finance-tracker/finance.js index ac2118f..25d7a7a 100644 --- a/finance-tracker/finance.js +++ b/finance-tracker/finance.js @@ -1,27 +1,87 @@ -function addTransaction(transaction) { - // TODO: Implement this function +const transactions = require('./data'); +const chalk = require('chalk'); + +function addTransaction(newTransaction) { + transactions.push({ ...newTransaction }); } function getTotalIncome() { - // TODO: Implement this function + let sum = 0; + for (const t of transactions) { + if (t.type === 'income') { + sum += t.amount; + } + } + return sum; } function getTotalExpenses() { - // TODO: Implement this function + let sum = 0; + for (const t of transactions) { + if (t.type === 'expense') { + sum += t.amount; + } + } + return sum; } function getBalance() { - // TODO: Implement this function + return getTotalIncome() - getTotalExpenses(); } function getTransactionsByCategory(category) { - // TODO: Implement this function + let filtered = []; + for (const t of transactions) { + if (t.category === category) { + filtered.push(t); + } + } + return filtered; } function getLargestExpense() { - // TODO: Implement this function + let largest = { amount: 0, description: 'None' }; + for (const t of transactions) { + if (t.type === 'expense' && t.amount > largest.amount) { + largest = t; + } + } + return largest; } function printAllTransactions() { - // TODO: Implement this function -} \ No newline at end of file + console.log(chalk.bold.yellow('\nšŸ’° PERSONAL FINANCE TRACKER šŸ’°')); + console.log('\nAll Transactions:'); + + transactions.forEach((t, index) => { + const { type, description, amount, category } = t; + + const label = + type === 'income' ? chalk.green('[INCOME]') : chalk.red('[EXPENSE]'); + const categoryStyled = chalk.yellow(category); + + console.log( + `${index + 1}. ${label} ${description} - €${amount} (${categoryStyled})` + ); + }); +} + +function printSummary() { + const balance = getBalance(); + const balanceColor = balance >= 0 ? chalk.cyan : chalk.red; + + console.log(chalk.bold('\nšŸ“Š FINANCIAL SUMMARY šŸ“Š')); + console.log(`Total Income: ${chalk.green('€' + getTotalIncome())}`); + console.log(`Total Expenses: ${chalk.red('€' + getTotalExpenses())}`); + console.log(`Current Balance: ${balanceColor('€' + balance)}`); + + const largest = getLargestExpense(); + console.log(`\nLargest Expense: ${largest.description} (€${largest.amount})`); + console.log(`Total Transactions: ${transactions.length}\n`); +} + +module.exports = { + addTransaction, + printAllTransactions, + printSummary, +}; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..52239c6 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,86 @@ +{ + "name": "c55-core-week-4", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "c55-core-week-4", + "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/package.json b/package.json new file mode 100644 index 0000000..3dee2d3 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "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": "app.js", + "scripts": { + "format": "prettier --write .", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/noneeeed/c55-core-week-4.git" + }, + "keywords": [], + "author": "Bader", + "license": "ISC", + "type": "commonjs", + "bugs": { + "url": "https://github.com/noneeeed/c55-core-week-4/issues" + }, + "homepage": "https://github.com/noneeeed/c55-core-week-4#readme", + "dependencies": { + "chalk": "^4.1.2" + } +}