Skip to content

Commit ee4024c

Browse files
author
Jin Xu
committed
course wesbos#18 finished
1 parent c463fcd commit ee4024c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

18 - Adding Up Times with Reduce/index-START.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,22 @@
182182
</li>
183183

184184
<script>
185+
// ugly way:
186+
// var totalSeconds = 0;
187+
// [...document.querySelectorAll('[data-time]')].forEach(ele => {
188+
// var arr = ele.getAttribute('data-time').split(':');
189+
// totalSeconds += Number((arr[0])) * 60 + Number((arr[1]));
190+
// })
191+
192+
// elegant way:
193+
var totalSeconds = [...document.querySelectorAll('[data-time]')]
194+
.map(ele => ele.getAttribute('data-time').split(':'))
195+
.map(arr => Number((arr[0])) * 60 + Number((arr[1])))
196+
.reduce((prev, current) => prev += current, 0);
197+
198+
console.log(`%c Video length: ${parseInt(totalSeconds / 3600)} hours,
199+
${parseInt((totalSeconds % 3600) / 60 )} minutes,
200+
${parseInt((totalSeconds % 3600) % 60 )} seconds.`, 'font-size: 20px;color: red')
185201
</script>
186202
</body>
187203
</html>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
15. [x] ~~LocalStorage~~
2222
16. [x] ~~Mouse Move Shadow~~
2323
17. [x] ~~Sort Without Articles~~
24-
18. [ ] Adding Up Times with Reduce
24+
18. [x] ~~Adding Up Times with Reduce~~
2525
19. [ ] Webcam Fun
2626
20. [ ] Speech Detection
2727
21. [ ] Geolocation

0 commit comments

Comments
 (0)