Skip to content
Open
157 changes: 0 additions & 157 deletions .gitignore
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-*

6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"semi": true,
"trailingComma": "es5",
"printWidth": 80
}
3 changes: 3 additions & 0 deletions finance-tracker/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This is the entrypoint for your application.
// node app.js




54 changes: 53 additions & 1 deletion finance-tracker/data.js
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 };
36 changes: 36 additions & 0 deletions finance-tracker/finance.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
const { transactions } = require("./data.js");

function addTransaction(transaction) {
// TODO: Implement this function
let maxId = 0;
for (let i = 0; i < transactions.length; i++) {

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!

if (transactions[i].id > maxId) {
maxId = transactions[i].id;
}
}
transaction.id = maxId + 1;

transactions.push(transaction);
console.log("→ 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 = [];

Choose a reason for hiding this comment

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

found can be a const since you don't change the object found points to. You only add things to it.

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

}

function printAllTransactions() {
Expand Down
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.

Loading