Skip to content

Commit ecf22df

Browse files
committed
Completed Excercise.
1 parent 2c124c2 commit ecf22df

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

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

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

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

0 commit comments

Comments
 (0)