Skip to content
Open
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
72 changes: 67 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,73 @@
// Entry
class Entry {}
// Entry
class Entry {
constructor(date, amount, description) {
this.date = date;
this.amount = amount;
this.description = description;
}
}

Entry.prototype.getFormattedAmount = function() {
return `${this.amount} €`;
};


// Income
class Income {}

class Income extends Entry {
constructor(date, amount, description) {
super(date, amount, description);
this.type = "income";
}
}

// Expense
class Expense {}

class Expense extends Entry {
constructor(date, amount, description, paid) {
super(date, amount, description);
this.paid = paid;
this.type = "expense";
}
}
Expense.prototype.getFormattedAmount = function() {
return `-${this.amount} €`;
};



// Budget
class Budget {}
class Budget {
constructor() {
this.entries = [];
}
addEntry(entry) {
this.entries.push(entry);
}
getCurrentBalance() {
let totalIncome = 0;
let totalExpenses = 0;

for (const entry of this.entries) {
if (entry.type === "income") {
totalIncome += entry.amount;
} else if (entry.type === "expense") {
totalExpenses += entry.amount;
}
}

return totalIncome - totalExpenses;
}
}

// BONUS Get Formatted Entries

Budget.prototype.getFormattedEntries = function() {
const formattedEntries = [];
this.entries.forEach(entry => {
formattedEntries.push(
`${entry.date} | ${entry.description} | ${entry.getFormattedAmount()}`
);
});
return formattedEntries;
}