Skip to content

Commit 4cedce2

Browse files
committed
Implement 18
1 parent aea0dce commit 4cedce2

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@
182182
</li>
183183
</ul>
184184
<script>
185+
const videos = Array.from(document.querySelectorAll('.videos > li'))
186+
const videoTimes = videos.map((video) => {
187+
return video.dataset.time
188+
})
189+
190+
const totalTime = videoTimes.reduce((sum, time) => {
191+
const [minutes, seconds] = time.split(':')
192+
sum += parseInt(minutes) * 60
193+
sum += parseInt(seconds)
194+
return sum
195+
}, 0)
196+
console.log(totalTime)
185197
</script>
186198
</body>
187199
</html>

0 commit comments

Comments
 (0)