We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2c3879b commit b5db78fCopy full SHA for b5db78f
18 - Adding Up Times with Reduce/index-START.html
@@ -182,6 +182,24 @@
182
</li>
183
184
<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
203
</script>
204
</body>
205
</html>
0 commit comments