File tree Expand file tree Collapse file tree
18 - Adding Up Times with Reduce Expand file tree Collapse file tree Original file line number Diff line number Diff line change 182182 </ li >
183183 </ ul >
184184< script >
185+ const timeNodes = [ ...document . querySelectorAll ( '[data-time]' ) ] ;
186+ const seconds = timeNodes
187+ . map ( node => node . dataset . time )
188+ . map ( timeCode => {
189+ const [ mins , secs ] = timeCode . split ( ':' ) . map ( parseFloat ) ;
190+ return ( mins * 60 ) + secs ;
191+ console . log ( mins , secs ) ;
192+ } )
193+ . reduce ( ( total , vidSeconds ) => total + vidSeconds )
194+
195+ let secondsLeft = seconds ;
196+ //const hours = Math.floor(secondsLeft / 3600);
197+ const hours = parseInt ( secondsLeft / 3600 ) ;
198+ const minsLeft = secondsLeft % 3600 ;
199+ const mins = parseInt ( minsLeft / 60 ) ;
200+ const secsLeft = minsLeft % 60 ;
201+ //const secs = parseInt(mins / 60);
202+ //const mins = Math.floor(secondsLeft / 60);
203+ console . log ( hours , mins , secsLeft ) ;
185204</ script >
186205</ body >
187206</ html >
You can’t perform that action at this time.
0 commit comments