@@ -81,19 +81,28 @@ const inputClosePin = document.querySelector('.form__input--pin');
81
81
/////////////////////////////////////////////////
82
82
// Functions
83
83
84
- const displayMovements = function ( movements , sort = false ) {
84
+ const displayMovements = function ( acc , sort = false ) {
85
85
containerMovements . innerHTML = '' ;
86
86
87
- const movs = sort ? movements . slice ( ) . sort ( ( a , b ) => a - b ) : movements ;
87
+ const movs = sort
88
+ ? acc . movements . slice ( ) . sort ( ( a , b ) => a - b )
89
+ : acc . movements ;
88
90
89
91
movs . forEach ( function ( mov , i ) {
90
92
const type = mov > 0 ? 'deposit' : 'withdrawal' ;
91
93
94
+ const date = new Date ( acc . movementsDates [ i ] ) ;
95
+ const day = `${ date . getDate ( ) } ` . padStart ( 2 , 0 ) ;
96
+ const month = `${ date . getMonth ( ) + 1 } ` . padStart ( 2 , 0 ) ;
97
+ const year = date . getFullYear ( ) ;
98
+ const displayDate = `${ day } /${ month } /${ year } ` ;
99
+
92
100
const html = `
93
101
<div class="movements__row">
94
102
<div class="movements__type movements__type--${ type } ">${
95
103
i + 1
96
104
} ${ type } </div>
105
+ <div class="movements__date">${ displayDate } </div>
97
106
<div class="movements__value">${ mov } €</div>
98
107
</div>
99
108
` ;
@@ -142,7 +151,7 @@ createUsernames(accounts);
142
151
143
152
const updateUI = function ( acc ) {
144
153
// Display movements
145
- displayMovements ( acc . movements ) ;
154
+ displayMovements ( acc ) ;
146
155
147
156
// Display balance
148
157
calcDisplayBalance ( acc ) ;
@@ -153,7 +162,31 @@ const updateUI = function (acc) {
153
162
154
163
///////////////////////////////////////
155
164
// Event handlers
156
- let currentAccount ;
165
+ let currentAccount = account1 ;
166
+ // FAKED LOGIN
167
+ updateUI ( currentAccount ) ;
168
+ containerApp . style . opacity = 100 ;
169
+
170
+ const today = new Date ( ) ;
171
+ const options = {
172
+ hour : 'numeric' ,
173
+ minute : 'numeric' ,
174
+ day : 'numeric' ,
175
+ month : 'long' ,
176
+ year : '2-digit' ,
177
+ weekday : 'long' ,
178
+ } ;
179
+
180
+ const locale = navigator . language ;
181
+ console . log ( locale ) ;
182
+
183
+ const day = `${ today . getDate ( ) } ` . padStart ( 2 , 0 ) ;
184
+ const month = `${ today . getMonth ( ) + 1 } ` . padStart ( 2 , 0 ) ;
185
+ const year = today . getFullYear ( ) ;
186
+ const hours = `${ today . getHours ( ) } ` . padStart ( 2 , 0 ) ;
187
+ const minutes = `${ today . getMinutes ( ) } ` . padStart ( 2 , 0 ) ;
188
+ // labelDate.textContent = `${day}/${month}/${year}, ${hours}:${minutes}`;
189
+ labelDate . textContent = new Intl . DateTimeFormat ( locale , options ) . format ( today ) ;
157
190
158
191
btnLogin . addEventListener ( 'click' , function ( e ) {
159
192
// Prevent form from submitting
@@ -335,17 +368,17 @@ checkEvenOdd(22);
335
368
checkEvenOdd ( 16 ) ;
336
369
checkEvenOdd ( 3 ) ;
337
370
338
- labelBalance . addEventListener ( 'click' , function ( ) {
339
- [ ...document . querySelectorAll ( '.movements__row' ) ] . forEach ( function (
340
- row ,
341
- index
342
- ) {
343
- // 0, 2, 4, 6, ...
344
- if ( index % 2 === 0 ) row . style . backgroundColor = 'orangered' ;
345
- // 0, 3, 6, 9, ...
346
- if ( index % 3 === 0 ) row . style . backgroundColor = 'blue' ;
347
- } ) ;
348
- } ) ;
371
+ // labelBalance.addEventListener('click', function () {
372
+ // [...document.querySelectorAll('.movements__row')].forEach(function (
373
+ // row,
374
+ // index
375
+ // ) {
376
+ // // 0, 2, 4, 6, ...
377
+ // if (index % 2 === 0) row.style.backgroundColor = 'orangered';
378
+ // // 0, 3, 6, 9, ...
379
+ // if (index % 3 === 0) row.style.backgroundColor = 'blue';
380
+ // });
381
+ // });
349
382
350
383
// 🔸Working with BigInt🔸
351
384
console . log ( 2 ** 53 - 1 ) ;
@@ -407,5 +440,46 @@ console.log(new Date(872173385000)); // get date based off timestamps
407
440
console . log ( Date . now ( ) ) ;
408
441
409
442
// date set() methods
410
- future . setFullYear ( 2099 ) ;
443
+ // future.setFullYear(2099);
411
444
console . log ( future ) ;
445
+ console . log ( Number ( future ) ) ; // convert date to timestamp(How many miliseconds that have passed since the invention of Unix time)
446
+ console . log ( + future ) ;
447
+
448
+ const calcDaysPassed = ( date1 , date2 ) =>
449
+ Math . abs ( ( date2 - date1 ) / ( 24 * 60 * 60 * 1000 ) ) ;
450
+ const days1 = calcDaysPassed ( new Date ( 2022 , 3 , 14 ) , new Date ( 2022 , 3 , 24 ) ) ;
451
+ console . log ( days1 ) ;
452
+
453
+ const option = {
454
+ style : 'currency' ,
455
+ unit : 'mile-per-hour' ,
456
+ currency : 'EUR' ,
457
+ // useGrouping: false,
458
+ } ;
459
+
460
+ const numbs = 2323253 ;
461
+ console . log ( 'US:' , new Intl . NumberFormat ( 'en-US' , option ) . format ( numbs ) ) ;
462
+ console . log ( 'Germany:' , new Intl . NumberFormat ( 'de-DE' , option ) . format ( numbs ) ) ;
463
+ console . log ( 'Syria:' , new Intl . NumberFormat ( 'ar-SY' , option ) . format ( numbs ) ) ;
464
+ console . log (
465
+ navigator . language ,
466
+ new Intl . NumberFormat ( navigator . language ) . format ( numbs )
467
+ ) ;
468
+
469
+ // 🔸Timers setTimeout and setInterval🔸
470
+ // setTimeout
471
+ const ingredients = [ 'olives' , 'spinach' ] ;
472
+ const pizzaTimer = setTimeout (
473
+ ( ing1 , ing2 ) => console . log ( `Here is your pizza 🍕 with ${ ing1 } & ${ ing2 } ` ) ,
474
+ 3000 ,
475
+ ...ingredients
476
+ ) ;
477
+ console . log ( 'Waiting...' ) ;
478
+
479
+ if ( ingredients . includes ( 'spinach' ) ) clearTimeout ( pizzaTimer ) ;
480
+
481
+ // setInterval
482
+ setInterval ( function ( ) {
483
+ const now = new Date ( ) ;
484
+ console . log ( now ) ;
485
+ } , 1000 ) ;
0 commit comments