Skip to content

Commit 043d11f

Browse files
committed
adding script wesbos#18
1 parent 5c8fcc4 commit 043d11f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

0 commit comments

Comments
 (0)