We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2c124c2 commit ecf22dfCopy full SHA for ecf22df
1 file changed
18 - Adding Up Times with Reduce/index-START.html
@@ -182,6 +182,25 @@
182
</li>
183
184
<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
204
</script>
205
</body>
206
</html>
0 commit comments