-
Notifications
You must be signed in to change notification settings - Fork 19
Diana C. #1
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
base: main
Are you sure you want to change the base?
Diana C. #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,3 +156,5 @@ dist | |
| vite.config.js.timestamp-* | ||
| vite.config.ts.timestamp-* | ||
|
|
||
| node_modules/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
| "score": 75, | ||
| "pass": true, | ||
| "passingScore": 50 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "semi": true, | ||
| "singleQuote": true, | ||
| "tabWidth": 2, | ||
| "trailingComma": "es5", | ||
| "printWidth": 80 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| # Core program week 4 assignment | ||
|
|
||
| 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 | ||
|
|
||
| ## Implementation Instructions | ||
| - Implement the requirements in the `finance-tracker` folder. | ||
| - Use the existing file structure. | ||
|
|
||
| - Implement the requirements in the `finance-tracker` folder. | ||
| - Use the existing file structure. | ||
| - You are allowed to create additional files if needed. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| // This is the entrypoint for your application. | ||
| // node app.js | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,45 @@ | ||
| // 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', | ||
| }, | ||
| ]; | ||
|
|
||
| export { transactions }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,132 @@ | ||
| import { transactions } from './data.js'; | ||
|
|
||
|
|
||
| import chalk from 'chalk'; | ||
|
|
||
| console.log(chalk.bold('💰 PERSONAL FINANCE TRACKER 💰')); | ||
|
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. Move these lines to This file |
||
| console.log(''); | ||
| console.log('Transactions count:', transactions.length); | ||
|
|
||
|
|
||
| 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; | ||
| } | ||
|
|
||
| // console.log('Total income:', getTotalIncome()); | ||
|
|
||
|
|
||
| function getTotalExpenses() { | ||
| // TODO: Implement this function | ||
| let totalExpenses = 0; | ||
|
|
||
| for (let i = 0; i < transactions.length; i++) { | ||
| if (transactions[i].type === 'expense') { | ||
| totalExpenses += transactions[i].amount; | ||
| } | ||
| } | ||
|
|
||
| return totalExpenses; | ||
| } | ||
|
|
||
| function getBalance() { | ||
| // TODO: Implement this function | ||
| const income = getTotalIncome(); | ||
| const expenses = getTotalExpenses(); | ||
|
|
||
| return income - expenses; | ||
| } | ||
| // console.log('Balance:', getBalance()); | ||
|
|
||
| function getTransactionsByCategory(category) { | ||
| // TODO: Implement this function | ||
| const result = []; | ||
|
|
||
| for (const transaction of transactions) { | ||
| if (transaction.category === category) { | ||
| result.push(transaction); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| // console.log('Food transactions:', getTransactionsByCategory('food')); | ||
|
|
||
| function getLargestExpense() { | ||
| // TODO: Implement this function | ||
| let largest = null; | ||
|
|
||
| for (const transaction of transactions) { | ||
| if (transaction.type === 'expense') { | ||
| if (largest === null || transaction.amount > largest.amount) { | ||
| largest = transaction; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return largest; | ||
| } | ||
| // console.log('Largest expense:', getLargestExpense()); | ||
|
|
||
| function printAllTransactions() { | ||
| // TODO: Implement this function | ||
| } | ||
| console.log(chalk.bold('All Transactions:')); | ||
|
|
||
| for (const transaction of transactions) { | ||
| const { id, type, description, amount, category } = transaction; | ||
|
|
||
| const label = `[${type.toUpperCase()}]`; | ||
|
|
||
| const amountText = | ||
| type === 'income' ? chalk.green(`€${amount}`) : chalk.red(`€${amount}`); | ||
|
|
||
| const categoryText = chalk.yellow(category); | ||
|
|
||
| console.log(`${id}. ${label} ${description} - ${amountText} (${categoryText})`); | ||
| } | ||
|
|
||
| console.log(''); | ||
| } | ||
|
|
||
| printAllTransactions(); | ||
|
|
||
|
|
||
|
|
||
| function printSummary() { | ||
| const totalIncome = getTotalIncome(); | ||
| const totalExpenses = getTotalExpenses(); | ||
| const balance = getBalance(); | ||
| const count = transactions.length; | ||
| const largestExpense = getLargestExpense(); | ||
|
|
||
| console.log(chalk.bold('📊 FINANCIAL SUMMARY 📊')); | ||
|
|
||
| console.log(chalk.bold(`Total income: €${totalIncome}`)); | ||
| console.log(chalk.bold(`Total expenses: €${totalExpenses}`)); | ||
|
|
||
| const balanceText = | ||
| balance >= 0 ? chalk.cyan(`€${balance}`) : chalk.red(`€${balance}`); | ||
| console.log(chalk.bold(`Current balance: ${balanceText}`)); | ||
|
|
||
| console.log(chalk.bold(`Total transactions: ${count}`)); | ||
|
|
||
| if (largestExpense) { | ||
| console.log( | ||
| chalk.bold( | ||
| `Largest expense: ${largestExpense.description} (€${largestExpense.amount})` | ||
| ) | ||
| ); | ||
| } else { | ||
| console.log(chalk.bold('Largest expense: none')); | ||
| } | ||
|
|
||
| console.log(''); | ||
| } | ||
|
|
||
| printSummary(); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "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", | ||
| "format": "prettier --write ." | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/dianadenwik/c55-core-week-4.git" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "type": "module", | ||
| "bugs": { | ||
| "url": "https://github.com/dianadenwik/c55-core-week-4/issues" | ||
| }, | ||
| "homepage": "https://github.com/dianadenwik/c55-core-week-4#readme", | ||
| "dependencies": { | ||
| "chalk": "^4.1.2" | ||
| }, | ||
| "devDependencies": { | ||
| "prettier": "^3.8.1" | ||
| } | ||
| } |
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.
Remove extra lines between import statements. Not a deal breaker, but preferred way to format files.