Skip to content

Commit 91d7c9e

Browse files
committed
18th exercise done
1 parent 7158ff7 commit 91d7c9e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

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

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

184184
<script>
185+
const timeNodes = Array.from(document.querySelectorAll('[data-time]'));
186+
const seconds = timeNodes
187+
.map(node => node.dataset.time)
188+
.map(timeCode => {
189+
const [mins, secs] = timeCode.split(':').map(parseFloat);
190+
return (mins * 60) + secs;
191+
})
192+
.reduce((total, vidSeconds) => total + vidSeconds);
193+
194+
let secondsLeft = seconds;
195+
const hours = Math.floor(secondsLeft / 3600);
196+
secondsLeft = secondsLeft % 3600;
197+
198+
const mins = Math.floor(secondsLeft / 60);
199+
secondsLeft = secondsLeft % 60;
200+
201+
console.log(hours, mins, secondsLeft);
185202
</script>
186203
</body>
187204
</html>

0 commit comments

Comments
 (0)