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 ( )
0 commit comments