@@ -81,19 +81,28 @@ const inputClosePin = document.querySelector('.form__input--pin');
8181/////////////////////////////////////////////////
8282// Functions
8383
84- const displayMovements = function ( movements , sort = false ) {
84+ const displayMovements = function ( acc , sort = false ) {
8585 containerMovements . innerHTML = '' ;
8686
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 ;
8890
8991 movs . forEach ( function ( mov , i ) {
9092 const type = mov > 0 ? 'deposit' : 'withdrawal' ;
9193
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+
92100 const html = `
93101 <div class="movements__row">
94102 <div class="movements__type movements__type--${ type } ">${
95103 i + 1
96104 } ${ type } </div>
105+ <div class="movements__date">${ displayDate } </div>
97106 <div class="movements__value">${ mov } €</div>
98107 </div>
99108 ` ;
@@ -142,7 +151,7 @@ createUsernames(accounts);
142151
143152const updateUI = function ( acc ) {
144153 // Display movements
145- displayMovements ( acc . movements ) ;
154+ displayMovements ( acc ) ;
146155
147156 // Display balance
148157 calcDisplayBalance ( acc ) ;
@@ -153,7 +162,31 @@ const updateUI = function (acc) {
153162
154163///////////////////////////////////////
155164// 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 ) ;
157190
158191btnLogin . addEventListener ( 'click' , function ( e ) {
159192 // Prevent form from submitting
@@ -335,17 +368,17 @@ checkEvenOdd(22);
335368checkEvenOdd ( 16 ) ;
336369checkEvenOdd ( 3 ) ;
337370
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+ // });
349382
350383// 🔸Working with BigInt🔸
351384console . log ( 2 ** 53 - 1 ) ;
@@ -407,5 +440,46 @@ console.log(new Date(872173385000)); // get date based off timestamps
407440console . log ( Date . now ( ) ) ;
408441
409442// date set() methods
410- future . setFullYear ( 2099 ) ;
443+ // future.setFullYear(2099);
411444console . 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