Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,5 @@ dist
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

node_modules/

2 changes: 1 addition & 1 deletion .hyf/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Auto grade tool

## How it works

1. The auto grade tool runs the `test.sh` script located in this directory.
2. `test.sh` should write to a file named `score.json` with following JSON format:
```json
Expand All @@ -12,4 +13,3 @@
```
All scores are out of 100. It is up to the assignment to determine how to calculate the score.
3. The auto grade runs via a github action on PR creation and updates the PR with the score.

2 changes: 1 addition & 1 deletion .hyf/score.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"score": 75,
"pass": true,
"passingScore": 50
}
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 80
}
6 changes: 4 additions & 2 deletions README.md
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.
1 change: 0 additions & 1 deletion finance-tracker/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// This is the entrypoint for your application.
// node app.js

45 changes: 44 additions & 1 deletion finance-tracker/data.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 };
121 changes: 113 additions & 8 deletions finance-tracker/finance.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,132 @@
import { transactions } from './data.js';

Copy link

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.


import chalk from 'chalk';

console.log(chalk.bold('💰 PERSONAL FINANCE TRACKER 💰'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these lines to app.js. This file is the entry point and statements that should be executed like console.log() and your functions should be called in app.js.

This file finance.js should have only your functions.

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();
105 changes: 105 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions package.json
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"
}
}
Loading