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
52 changes: 48 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
// Entry
class Entry {}
class Entry {
constructor(date, amount, description) {
this.date = date;
this.amount = amount;
this.description = description;
}
getFormattedAmount() {
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";
}
getFormattedAmount() {
return `-${this.amount} €`; // Override to include the minus sign
}
}

// Budget
class Budget {}
class Budget {
constructor(){
this.entries = [];
}
addEntry(newEntry){
this.entries.push(newEntry)
}
getCurrentBalance(){
let total = 0;
for(let i = 0; i<this.entries.length; i++){
const currentEntry= this.entries[i];
if(currentEntry.type === 'income'){
total += currentEntry.amount;
}
else if (currentEntry.type === 'expense'){
total -= currentEntry.amount;
}
}
return total;
}
}