Skip to content

Commit b5db78f

Browse files
committed
Completed lesson 18
mins, sex, and deuces
1 parent 2c3879b commit b5db78f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@
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, seconds) => total + seconds);
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);
202+
185203
</script>
186204
</body>
187205
</html>

0 commit comments

Comments
 (0)