File tree 4 files changed +61
-1
lines changed
4 files changed +61
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Tally String Times with Reduce
2
+ Watch this challenge live in [ codepen] ( https://codepen.io/pouyio/full/awLmLd/ ) .
Original file line number Diff line number Diff line change
1
+ window . onload = ( ) => {
2
+
3
+ const timeNodes = Array . from ( document . querySelectorAll ( '[data-time]' ) ) ;
4
+
5
+ const seconds = timeNodes . reduce ( ( acc , timeNode ) => {
6
+ const [ mins , secs ] = timeNode . dataset . time . split ( '.' ) . map ( parseFloat ) ;
7
+ return acc + secs + mins * 60 ;
8
+ } , 0 ) ;
9
+
10
+ let secondsLeft = seconds ;
11
+ const hours = Math . floor ( secondsLeft / 3600 ) ;
12
+ secondsLeft = secondsLeft % 3600 ;
13
+
14
+ const minutes = Math . floor ( secondsLeft / 60 ) ;
15
+ secondsLeft = ( secondsLeft % 60 ) ;
16
+
17
+ document . querySelector ( '.total' ) . innerText = `${ hours } .${ minutes } .${ secondsLeft } ` ;
18
+
19
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Tally String Times with Reduce</ title >
6
+ < style media ="screen ">
7
+ body {
8
+ font-family : sans-serif;
9
+ font-size : 1.8em ;
10
+ color : # 383838 ;
11
+ min-height : 100vh ;
12
+ margin : 0 ;
13
+ padding : 1em ;
14
+ box-sizing : border-box;
15
+ background-color : # e7e4e4 ;
16
+ display : flex;
17
+ flex-direction : column;
18
+ justify-content : space-around;
19
+ align-items : center;
20
+ }
21
+ h1 {
22
+ text-align : center;
23
+ }
24
+ </ style >
25
+ </ head >
26
+ < body >
27
+ < ul >
28
+ < li data-time ="3.40 "> Video 1: 3.40</ li >
29
+ < li data-time ="1.20 "> Video 2: 1.20</ li >
30
+ < li data-time ="2.42 "> Video 3: 2.42</ li >
31
+ < li data-time ="4.53 "> Video 4: 4.53</ li >
32
+ < li data-time ="1.00 "> Video 5: 1.00</ li >
33
+ < li data-time ="2.06 "> Video 6: 2.06</ li >
34
+ </ ul >
35
+ < p > Total < span class ="total "> </ span > </ p >
36
+ < script type ="text/javascript " src ="./app.js ">
37
+ </ script >
38
+ </ body >
39
+ </ html >
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ My goal is simply to learn the basics by doing many simple things rather than st
22
22
15 . [x] [ LocalStorage] ( ./15-localStorage ) - [ Codepen] ( https://codepen.io/pouyio/full/XgRpOd/ )
23
23
16 . [x] [ CSS Text Shadow Mouse Move Effect] ( ./16-text-shadow ) - [ Codepen] ( https://codepen.io/pouyio/full/mwweaq/ )
24
24
17 . [x] [ Sort Without Articles] ( ./17-sorting-without-articles ) - [ Codepen] ( https://codepen.io/pouyio/full/WOOrOV/ )
25
- 18 . [ ] Adding Up Times with Reduce
25
+ 18 . [x] [ Tally String Times with Reduce] ( ./18-tally-strings ) - [ Codepen ] ( https://codepen.io/pouyio/full/awLmLd/ )
26
26
19 . [ ] Webcam Fun
27
27
20 . [ ] Speech Detection
28
28
21 . [ ] Geolocation
You can’t perform that action at this time.
0 commit comments