generated from HackYourFuture/core-assignment-week-4
-
Notifications
You must be signed in to change notification settings - Fork 19
Yusup R. #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yusuprozimemet
wants to merge
4
commits into
HackYourAssignment:main
Choose a base branch
from
Yusuprozimemet:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Yusup R. #16
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| { | ||
| "semi": true, | ||
| "singleQuote": true, | ||
| "tabWidth": 2, | ||
| "trailingComma": "es5", | ||
| "printWidth": 80 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,40 @@ | ||
| // This is the entrypoint for your application. | ||
| // node app.js | ||
| const chalk = require('chalk'); | ||
| const data = require('./data'); | ||
| const transactions = data.transactions; | ||
|
|
||
| const { | ||
| addTransaction, | ||
| getTotalIncome, | ||
| getTotalExpenses, | ||
| getBalance, | ||
| getTransactionsByCategory, | ||
| getLargestExpense, | ||
| printAllTransactions | ||
| } = require('./finance'); | ||
|
|
||
| // Example usage of the functions | ||
| console.log(chalk.blue('💰 PERSONAL FINANCE TRACKER 💰')); | ||
|
|
||
| printAllTransactions(transactions); | ||
|
|
||
| console.log('\n📊 FINANCIAL SUMMARY 📊'); | ||
| console.log(chalk.bold('Total Income:') + chalk.green(` €${getTotalIncome(transactions)}`)); | ||
| console.log(chalk.bold('Total Expenses:') + chalk.red(` €${getTotalExpenses(transactions)}`)); | ||
| console.log(chalk.bold('Current Balance:') + (getBalance(transactions) < 0 ? chalk.red : chalk.cyan)(` €${getBalance(transactions)}`)); | ||
|
|
||
| const largest = getLargestExpense(transactions); | ||
| if (largest) { | ||
| console.log(chalk.bold(`\nLargest Expense: ${largest.category} (€${largest.amount})`)); | ||
| } | ||
|
|
||
|
|
||
| console.log(chalk.bold(`Total Transactions: ${transactions.length}`)); | ||
|
|
||
| addTransaction({ | ||
| id: 6, | ||
| type: 'expense', | ||
| category: 'entertainment', | ||
| amount: 200, | ||
| description: 'Concert tickets', | ||
| date: '2025-02-05' | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,43 @@ | ||
| // 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: '2025-01-15' | ||
| }, | ||
| {id: 2, | ||
| type: 'expense', | ||
| category: 'Rent', | ||
| amount: 1200, | ||
| description: 'housing', | ||
| date: '2025-01-25' | ||
| }, | ||
| {id: 3, | ||
| type: 'expense', | ||
| category: 'Groceries', | ||
| amount: 300, | ||
| description: 'food', | ||
| date: '2025-01-20' | ||
| }, | ||
|
|
||
| {id: 4, | ||
| type: 'income', | ||
| category: 'Freelance', | ||
| amount: 500, | ||
| description: 'side-income', | ||
| date: '2025-01-28' | ||
| }, | ||
| {id: 5, | ||
| type: 'expense', | ||
| category: 'Utilities', | ||
| amount: 150, | ||
| description: 'bills', | ||
| date: '2025-01-30' | ||
| } | ||
| ]; | ||
|
|
||
| module.exports = { | ||
| transactions | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,79 @@ | ||
| function addTransaction(transaction) { | ||
| // TODO: Implement this function | ||
| const chalk = require('chalk'); | ||
|
|
||
| let transactions = []; | ||
|
|
||
| function addTransaction(singleTransaction) { | ||
| const newTransaction = { ...singleTransaction }; | ||
| transactions.push(newTransaction); | ||
| } | ||
|
|
||
| function getTotalIncome(transactions) { | ||
| let total = 0; | ||
| for (const singleTransaction of transactions) { | ||
| if(singleTransaction.type === 'income') { | ||
| total += singleTransaction.amount; | ||
| } | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| function getTotalIncome() { | ||
| // TODO: Implement this function | ||
| function getTotalExpenses(transactions) { | ||
| let total = 0; | ||
| for (const singleTransaction of transactions) { | ||
| if(singleTransaction.type === 'expense') { | ||
| total += singleTransaction.amount; | ||
| } | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| function getTotalExpenses() { | ||
| // TODO: Implement this function | ||
| function getBalance(transactions) { | ||
| const income = getTotalIncome(transactions); | ||
| const expenses = getTotalExpenses(transactions); | ||
| return income - expenses; | ||
| } | ||
|
|
||
| function getBalance() { | ||
| // TODO: Implement this function | ||
| function getTransactionsByCategory(category, transactions) { | ||
| const results = []; | ||
| for (const singleTransaction of transactions) { | ||
| if(singleTransaction.category === category) { | ||
| results.push(singleTransaction); | ||
| } | ||
| } | ||
| return results; | ||
| } | ||
|
|
||
| function getTransactionsByCategory(category) { | ||
| // TODO: Implement this function | ||
| function getLargestExpense(transactions) { | ||
| let largest = null; | ||
| for (const singleTransaction of transactions) { | ||
| if(singleTransaction.type === 'expense') { | ||
| if(largest === null || singleTransaction.amount > largest.amount) { | ||
| largest = singleTransaction; | ||
| } | ||
| } | ||
| } | ||
| return largest; | ||
| } | ||
|
|
||
| function getLargestExpense() { | ||
| // TODO: Implement this function | ||
| function printAllTransactions(transactions) { | ||
| console.log('\nAll Transactions:'); | ||
| let index = 1; | ||
| for (const singleTransaction of transactions) { | ||
| const {id, type, category, amount, description} = singleTransaction; | ||
| const typeLabel = type === 'income' ? chalk.green('Income') : chalk.red('Expense'); | ||
| const coloredAmount = type === 'income' ? chalk.green(`${amount}`) : chalk.red(`${amount}`); | ||
| const coloredCategory = chalk.yellow(`${category}`); | ||
| console.log(`${index}. [${typeLabel}] ${coloredCategory} - ${coloredAmount} (${description})`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Label type should be fully uppercase and not colored. |
||
| index++; | ||
| } | ||
| } | ||
|
|
||
| function printAllTransactions() { | ||
| // TODO: Implement this function | ||
| } | ||
| module.exports = { | ||
| addTransaction, | ||
| getTotalIncome, | ||
| getTotalExpenses, | ||
| getBalance, | ||
| getTransactionsByCategory, | ||
| getLargestExpense, | ||
| printAllTransactions | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "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/Yusuprozimemet/c55-core-week-4.git" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "type": "commonjs", | ||
| "bugs": { | ||
| "url": "https://github.com/Yusuprozimemet/c55-core-week-4/issues" | ||
| }, | ||
| "homepage": "https://github.com/Yusuprozimemet/c55-core-week-4#readme", | ||
| "dependencies": { | ||
| "chalk": "^4.1.2" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting seems a bit odd here. Did you run prettier?