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 192192 return ( mins * 60 ) + secs ;
193193 } )
194194 . reduce ( ( total , vidSeconds ) => total + vidSeconds ) ;
195+ console . log ( seconds ) ;
195196
196197 let secondsLeft = seconds ;
197198 const hours = Math . floor ( secondsLeft / 3600 ) ;
Original file line number Diff line number Diff line change 182182 </ li >
183183 </ ul >
184184< script >
185+ const items = Array . from ( document . querySelectorAll ( '.videos li' ) ) ;
186+ const totalSeconds = items
187+ . map ( ( item ) => {
188+ const duration = item . dataset . time ;
189+ const [ minutes , seconds ] = duration . split ( ':' ) . map ( parseFloat ) ;
190+ return ( 60 * minutes ) + seconds ;
191+ } )
192+ . reduce ( ( seconds , cur ) => {
193+ return cur + seconds ;
194+ } , 0 ) ;
195+ const hours = Math . floor ( totalSeconds / 60 / 60 ) ;
196+ const minutesLeft = Math . floor ( ( totalSeconds - ( hours * 60 * 60 ) ) / 60 ) ;
197+ const secondsLeft = totalSeconds - ( hours * 60 * 60 ) - ( minutesLeft * 60 ) ;
198+ // console.log(totalSeconds);
199+ console . log ( `${ hours } :${ minutesLeft } :${ secondsLeft } ` ) ;
185200</ script >
186201</ body >
187202</ html >
You can’t perform that action at this time.
0 commit comments