Skip to content

Commit b23d7c5

Browse files
committed
keep moving forward
1 parent 4bcdc1a commit b23d7c5

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

expenseTracker/script.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
const balance = document.getElementById('balance');
3+
const money_plus = document.getElementById('money-plus');
4+
const money_minus = document.getElementById('money-minus');
5+
const list = document.getElementById('list');
6+
const form = document.getElementById('form');
7+
const text = document.getElementById('text');
8+
const amount = document.getElementById('amount');
9+
10+
11+
12+
const dummyTransactions = [
13+
{ id: 1, text: 'Flower', amount: -20 },
14+
{ id: 2, text: 'Salary', amount: 300 },
15+
{ id: 3, text: 'Book', amount: -10 },
16+
{ id: 4, text: 'Camera', amount: 150 }
17+
]
18+
19+
20+
let transactions = dummyTransactions
21+
22+
// Add transactions to DOM list
23+
24+
25+
function addTransactionDOM(transaction) {
26+
// Get sign
27+
28+
const sign = transaction.amount < 0 ? '-' : '+'
29+
30+
31+
const item = document.createElement('li')
32+
33+
34+
// add class based on value
35+
item.classList.add(transaction.amount < 0 ? 'minus' : 'plus')
36+
37+
38+
item.innerHTML = `${transaction.text} <span>${sign} ${Math.abs(transaction.amount)}</span> <button class="delete-btn"> X </button>`
39+
40+
41+
42+
43+
list.appendChild(item);
44+
45+
}
46+
47+
48+
// init app
49+
50+
function init() {
51+
list.innerHTML = ''
52+
53+
transactions.forEach(addTransactionDOM)
54+
}
55+
56+
57+
init()

expenseTracker/style.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ input[type='text'].input[type='number'] {
140140
}
141141

142142

143-
.li li.minus {
143+
.list li.minus {
144144
border-right: 5px solid #c0392b;
145145
}
146146

@@ -171,4 +171,5 @@ input[type='text'].input[type='number'] {
171171
.btn:focus,
172172
.delete-btn:focus {
173173
outline: 0;
174+
174175
}

0 commit comments

Comments
 (0)