Visitar URL original
Day 18 Complete · wesbos/JavaScript30@0c2226a · GitHub
Skip to content

Commit 0c2226a

Browse files
committed
Day 18 Complete
We added the seconds and shit dawg
1 parent bd8262d commit 0c2226a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

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

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

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

0 commit comments

Comments
 (0)