File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
18 - Adding Up Times with Reduce Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html lang ="en ">
3+
34< head >
45 < meta charset ="UTF-8 ">
56 < title > Videos</ title >
67</ head >
8+
79< body >
810 < ul class ="videos ">
911 < li data-time ="5:43 ">
181183 Video 58
182184 </ li >
183185 </ ul >
184- < script >
185- </ script >
186+ < script >
187+ function displayTime ( seconds ) {
188+ let secLeft = seconds ;
189+ const hh = Math . floor ( secLeft / 3600 ) ;
190+ secLeft = secLeft % 3600 ;
191+ const mm = Math . floor ( secLeft / 60 ) ;
192+ ss = secLeft % 60 ;
193+
194+ return `${ hh } :${ mm } :${ ss } ` ;
195+ }
196+
197+ const seconds = [ ...document . querySelectorAll ( '[data-time]' ) ]
198+ . map ( n => n . dataset . time )
199+ . map ( t => {
200+ const [ mins , secs ] = t . split ( ':' ) . map ( parseFloat ) ;
201+ return ( mins * 60 ) + secs ;
202+ } ) . reduce ( ( total , duration ) => total + duration ) ;
203+
204+ console . log ( 'Total time = ' + displayTime ( seconds ) ) ;
205+ </ script >
186206</ body >
187- </ html >
207+
208+ </ html >
You can’t perform that action at this time.
0 commit comments