generated from HackYourFuture/core-assignment-week-4
-
Notifications
You must be signed in to change notification settings - Fork 19
Hannah N #10
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
hannahwn
wants to merge
15
commits into
HackYourAssignment:main
Choose a base branch
from
hannahwn: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
Hannah N #10
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
119d5eb
initialized and installed chalk
hannahwn f46eaf2
setup prettier
hannahwn 5754282
created a prettier file
hannahwn e786176
added transaction objects
hannahwn 08f3b2b
adds transactions and gets total income
hannahwn 9dab125
gets total expenses
hannahwn c53e8bb
gets remaining money
hannahwn cf0621d
gets by category
hannahwn 873b584
gets largest expense
hannahwn 3dfdb12
prints all transactions
hannahwn 581eabf
added imports and exports
hannahwn 7b349c8
adds transaction and prints all
hannahwn f658fbe
prints all after adding transactions
hannahwn 3e1b0c9
finds largest expense
hannahwn b18e9c3
added chalk properties
hannahwn 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -1,158 +1 @@ | ||
| # System files | ||
| .DS_Store | ||
| Thumbs.db | ||
| [Dd]esktop.ini | ||
|
|
||
| # hyf | ||
| .hyf/score.json | ||
|
|
||
| # Editor and IDE settings | ||
| .vscode/ | ||
| .idea/ | ||
| *.iml | ||
| *.code-workspace | ||
| *.sublime-project | ||
| *.sublime-workspace | ||
| .history/ | ||
| .ionide/ | ||
|
|
||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| lerna-debug.log* | ||
|
|
||
| # Diagnostic reports (https://nodejs.org/api/report.html) | ||
| report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
|
||
| # Runtime data | ||
| pids | ||
| *.pid | ||
| *.seed | ||
| *.pid.lock | ||
|
|
||
| # Directory for instrumented libs generated by jscoverage/JSCover | ||
| lib-cov | ||
|
|
||
| # Coverage directory used by tools like istanbul | ||
| coverage | ||
| *.lcov | ||
|
|
||
| # nyc test coverage | ||
| .nyc_output | ||
|
|
||
| # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
| .grunt | ||
|
|
||
| # Bower dependency directory (https://bower.io/) | ||
| bower_components | ||
|
|
||
| # node-waf configuration | ||
| .lock-wscript | ||
|
|
||
| # Compiled binary addons (https://nodejs.org/api/addons.html) | ||
| build/Release | ||
|
|
||
| # Dependency directories | ||
| node_modules/ | ||
| jspm_packages/ | ||
|
|
||
| # Snowpack dependency directory (https://snowpack.dev/) | ||
| web_modules/ | ||
|
|
||
| # TypeScript cache | ||
| *.tsbuildinfo | ||
|
|
||
| # Optional npm cache directory | ||
| .npm | ||
|
|
||
| # Optional eslint cache | ||
| .eslintcache | ||
|
|
||
| # Optional stylelint cache | ||
| .stylelintcache | ||
|
|
||
| # Optional REPL history | ||
| .node_repl_history | ||
|
|
||
| # Output of 'npm pack' | ||
| *.tgz | ||
|
|
||
| # Yarn Integrity file | ||
| .yarn-integrity | ||
|
|
||
| # dotenv environment variable files | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
|
|
||
| # parcel-bundler cache (https://parceljs.org/) | ||
| .cache | ||
| .parcel-cache | ||
|
|
||
| # Next.js build output | ||
| .next | ||
| out | ||
|
|
||
| # Nuxt.js build / generate output | ||
| .nuxt | ||
| dist | ||
|
|
||
| # Gatsby files | ||
| .cache/ | ||
| # Comment in the public line in if your project uses Gatsby and not Next.js | ||
| # https://nextjs.org/blog/next-9-1#public-directory-support | ||
| # public | ||
|
|
||
| # vuepress build output | ||
| .vuepress/dist | ||
|
|
||
| # vuepress v2.x temp and cache directory | ||
| .temp | ||
| .cache | ||
|
|
||
| # Sveltekit cache directory | ||
| .svelte-kit/ | ||
|
|
||
| # vitepress build output | ||
| **/.vitepress/dist | ||
|
|
||
| # vitepress cache directory | ||
| **/.vitepress/cache | ||
|
|
||
| # Docusaurus cache and generated files | ||
| .docusaurus | ||
|
|
||
| # Serverless directories | ||
| .serverless/ | ||
|
|
||
| # FuseBox cache | ||
| .fusebox/ | ||
|
|
||
| # DynamoDB Local files | ||
| .dynamodb/ | ||
|
|
||
| # Firebase cache directory | ||
| .firebase/ | ||
|
|
||
| # TernJS port file | ||
| .tern-port | ||
|
|
||
| # Stores VSCode versions used for testing VSCode extensions | ||
| .vscode-test | ||
|
|
||
| # yarn v3 | ||
| .pnp.* | ||
| .yarn/* | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/sdks | ||
| !.yarn/versions | ||
|
|
||
| # Vite logs files | ||
| vite.config.js.timestamp-* | ||
| vite.config.ts.timestamp-* | ||
|
|
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,6 @@ | ||
| { | ||
| "singleQuote": true, | ||
| "semi": true, | ||
| "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,59 @@ | ||
| // This is the entrypoint for your application. | ||
| // node app.js | ||
| const { | ||
| addTransaction, | ||
| getTotalIncome, | ||
| getTotalExpenses, | ||
| getBalance, | ||
| getTransactionsByCategory, | ||
| getLargestExpense, | ||
| printAllTransactions, | ||
| } = require('./finance.js'); | ||
|
|
||
| console.log('Starting application...'); | ||
| printAllTransactions(); | ||
|
|
||
| console.log('Total income: €' + getTotalIncome().toFixed(2)); | ||
| console.log('Total expenses: €' + getTotalExpenses().toFixed(2)); | ||
| console.log('Current balance: €' + getBalance().toFixed(2)); | ||
|
|
||
| addTransaction({ | ||
| type: 'expense', | ||
| category: 'Food', | ||
| amount: 9.5, | ||
| description: 'Lunch sandwich', | ||
| }); | ||
|
|
||
| addTransaction({ | ||
| type: 'income', | ||
| category: 'Sale', | ||
| amount: 40, | ||
| description: 'Sold old headphones', | ||
| }); | ||
|
|
||
| console.log('\nAfter adding transactions:'); | ||
| printAllTransactions(); | ||
|
|
||
| console.log('New total income: €' + getTotalIncome().toFixed(2)); | ||
| console.log('New total expenses: €' + getTotalExpenses().toFixed(2)); | ||
| console.log('New balance: €' + getBalance().toFixed(2)); | ||
|
|
||
| console.log("All 'Food' transactions:"); | ||
| console.log(getTransactionsByCategory('Food')); | ||
|
|
||
| console.log('\nLargest expense:'); | ||
| const biggest = getLargestExpense(); | ||
| if (biggest) { | ||
| console.log( | ||
| '#' + | ||
| biggest.id + | ||
| ' ' + | ||
| biggest.category + | ||
| ' €' + | ||
| biggest.amount + | ||
| ' – ' + | ||
| biggest.description | ||
| ); | ||
| } else { | ||
| console.log('No expenses found.'); | ||
| } |
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,54 @@ | ||
| // 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-04' | ||
| }, | ||
| { | ||
| id: 2, | ||
| type: 'expense', | ||
| category: 'rent', | ||
| amount: 1000, | ||
| description: 'Pay for the house', | ||
| date: '2025-01-06' | ||
| }, | ||
| { | ||
| id: 3, | ||
| type: 'income', | ||
| category: 'Making hair', | ||
| amount: 5000, | ||
| description: 'Money earned working in the weekend', | ||
| date: '2025-01-29' | ||
| }, | ||
| { | ||
| id: 4, | ||
| type: 'expense', | ||
| category: 'travel card', | ||
| amount: 1500, | ||
| description: 'Pay NS for travel card', | ||
| date: '2025-01-26' | ||
| }, | ||
| { | ||
| id: 5, | ||
| type: 'expense', | ||
| category: 'tours', | ||
| amount: 2000, | ||
| description: 'Saving money for vacancy', | ||
| date: '2025-01-10' | ||
| }, | ||
| { | ||
| id: 6, | ||
| type: 'expense', | ||
| category: 'Subscriptions', | ||
| amount: 1000, | ||
| description: 'Busuu,Netflix,Spotify,Data', | ||
| date: '2025-01-15' | ||
| }, | ||
|
|
||
|
|
||
| ]; | ||
| 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,105 @@ | ||
| const chalk = require("chalk"); | ||
| const { transactions } = require("./data.js"); | ||
|
|
||
|
|
||
| function addTransaction(transaction) { | ||
| // TODO: Implement this function | ||
| let maxId = 0; | ||
| for (let i = 0; i < transactions.length; i++) { | ||
| if (transactions[i].id > maxId) { | ||
| maxId = transactions[i].id; | ||
| } | ||
| } | ||
| transaction.id = maxId + 1; | ||
|
|
||
| transactions.push(transaction); | ||
| console.log(chalk.green('→ Added transaction #' + transaction.id)); | ||
| } | ||
|
|
||
| function getTotalIncome() { | ||
| // TODO: Implement this function | ||
| let total = 0; | ||
| for (let i = 0; i < transactions.length; i++) { | ||
| if (transactions[i].type === 'income') { | ||
| total += transactions[i].amount; | ||
| } | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| function getTotalExpenses() { | ||
| // TODO: Implement this function | ||
| let total = 0; | ||
| for (let i = 0; i < transactions.length; i++) { | ||
| if (transactions[i].type === 'expense') { | ||
| total += transactions[i].amount; | ||
| } | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| function getBalance() { | ||
| // TODO: Implement this function | ||
| return getTotalIncome() - getTotalExpenses(); | ||
| } | ||
|
|
||
| function getTransactionsByCategory(category) { | ||
| // TODO: Implement this function | ||
| let found = []; | ||
| for (let i = 0; i < transactions.length; i++) { | ||
| if (transactions[i].category === category) { | ||
| found.push(transactions[i]); | ||
| } | ||
| } | ||
| return found; | ||
| } | ||
|
|
||
| function getLargestExpense() { | ||
| // TODO: Implement this function | ||
| let largest = null; | ||
| let maxAmount = -1; | ||
|
|
||
| for (let i = 0; i < transactions.length; i++) { | ||
| let t = transactions[i]; | ||
| if (t.type === 'expense' && t.amount > maxAmount) { | ||
| largest = t; | ||
| maxAmount = t.amount; | ||
| } | ||
| } | ||
| return largest; | ||
| } | ||
|
|
||
| function printAllTransactions() { | ||
| // TODO: Implement this function | ||
| } | ||
| console.log(chalk.bold('\n=== Transactions ===')); | ||
| console.log(chalk.bold('ID | Type | Amount | Category | Description')); | ||
| console.log('-----------------------------------------------'); | ||
|
|
||
| for (let i = 0; i < transactions.length; i++) { | ||
| let t = transactions[i]; | ||
| let sign = t.type === 'income' ? '+' : '-'; | ||
| console.log( | ||
| t.id + | ||
| ' | ' + | ||
| t.type.padEnd(8) + | ||
| ' | ' + | ||
| sign + | ||
| t.amount.toFixed(2).padStart(6) + | ||
| ' | ' + | ||
| t.category.padEnd(10) + | ||
| ' | ' + | ||
| t.description | ||
| ); | ||
| } | ||
| console.log('-----------------------------------------------\n'); | ||
| } | ||
|
|
||
| module.exports = { | ||
| addTransaction, | ||
| getTotalIncome, | ||
| getTotalExpenses, | ||
| getBalance, | ||
| getTransactionsByCategory, | ||
| getLargestExpense, | ||
| printAllTransactions, | ||
| }; | ||
Oops, something went wrong.
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.
nice... you think of adding an id property with a consecutive value to the transaction object. Bonus points!