Skip to content

Commit 6ee7613

Browse files
authored
Merge pull request #7 from pouyio/gh-pages
day 18
2 parents c0d82e4 + 249f532 commit 6ee7613

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

18-tally-strings/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Tally String Times with Reduce
2+
Watch this challenge live in [codepen](https://codepen.io/pouyio/full/awLmLd/).

18-tally-strings/app.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
window.onload = () => {
2+
3+
const timeNodes = Array.from(document.querySelectorAll('[data-time]'));
4+
5+
const seconds = timeNodes.reduce((acc, timeNode) => {
6+
const [mins, secs] = timeNode.dataset.time.split('.').map(parseFloat);
7+
return acc + secs + mins * 60;
8+
}, 0);
9+
10+
let secondsLeft = seconds;
11+
const hours = Math.floor(secondsLeft / 3600);
12+
secondsLeft = secondsLeft % 3600;
13+
14+
const minutes = Math.floor(secondsLeft / 60);
15+
secondsLeft = (secondsLeft % 60);
16+
17+
document.querySelector('.total').innerText = `${hours}.${minutes}.${secondsLeft}`;
18+
19+
}

18-tally-strings/index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Tally String Times with Reduce</title>
6+
<style media="screen">
7+
body{
8+
font-family: sans-serif;
9+
font-size: 1.8em;
10+
color: #383838;
11+
min-height: 100vh;
12+
margin: 0;
13+
padding: 1em;
14+
box-sizing: border-box;
15+
background-color: #e7e4e4;
16+
display: flex;
17+
flex-direction: column;
18+
justify-content: space-around;
19+
align-items: center;
20+
}
21+
h1 {
22+
text-align: center;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<ul>
28+
<li data-time="3.40">Video 1: 3.40</li>
29+
<li data-time="1.20">Video 2: 1.20</li>
30+
<li data-time="2.42">Video 3: 2.42</li>
31+
<li data-time="4.53">Video 4: 4.53</li>
32+
<li data-time="1.00">Video 5: 1.00</li>
33+
<li data-time="2.06">Video 6: 2.06</li>
34+
</ul>
35+
<p>Total <span class="total"></span></p>
36+
<script type="text/javascript" src="./app.js">
37+
</script>
38+
</body>
39+
</html>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ My goal is simply to learn the basics by doing many simple things rather than st
2222
15. [x] [LocalStorage](./15-localStorage) - [Codepen](https://codepen.io/pouyio/full/XgRpOd/)
2323
16. [x] [CSS Text Shadow Mouse Move Effect](./16-text-shadow) - [Codepen](https://codepen.io/pouyio/full/mwweaq/)
2424
17. [x] [Sort Without Articles](./17-sorting-without-articles) - [Codepen](https://codepen.io/pouyio/full/WOOrOV/)
25-
18. [ ] Adding Up Times with Reduce
25+
18. [x] [Tally String Times with Reduce](./18-tally-strings) - [Codepen](https://codepen.io/pouyio/full/awLmLd/)
2626
19. [ ] Webcam Fun
2727
20. [ ] Speech Detection
2828
21. [ ] Geolocation

0 commit comments

Comments
 (0)