Skip to content

Commit

Permalink
Weeks Remaining Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinDFuller committed Dec 22, 2024
1 parent 6a3bc2d commit 37df366
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 9 additions & 1 deletion make/remaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ function process(birthdate) {
const expectedWeeks = 79 * 52;
const expected = expectedWeeks - age

if (expected <= 0) {
document.getElementById("unexpected-results").style.display = "block";
document.getElementById("expected-results").style.display = "none";

return;
}

document.getElementById("age").innerText = age;
document.getElementById("remaining").innerText = expected;
document.getElementById("percent").innerText = Math.round(((expectedWeeks - age) / expectedWeeks) * 100);
document.getElementById("results").style.display = "block";
document.getElementById("expected-results").style.display = "block";
document.getElementById("unexpected-results").style.display = "none";
}

try {
Expand Down
21 changes: 20 additions & 1 deletion make/remaining.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2>When were you born?</h2>
<button type="submit">Calculate</button>
</form>
</section>
<section id="results" style="display: none">
<section id="expected-results" style="display: none">
<h2>Results</h2>
<p>
You are
Expand All @@ -45,6 +45,25 @@ <h2>Results</h2>
How will you use it?
</a>
</section>
<section id="unexpected-results" style="display: none">
<h2>Results</h2>
<p>
This calculator assumes an average life span of 79 years. The date you
indicated goes beyond this expectation. I'm sorry it can't produce a
useful result for you but thank you for giving it a try!
</p>
<p>
If this is unexpected, please check the date you entered and try
again.
</p>
<a
href="https://open.spotify.com/episode/5jD2kHfzXrG3vaOthJn3fj"
rel="noopener noreferrer"
target="_blank"
>
You may still enjoy this podcast episode.
</a>
</section>
</main>

<script>
Expand Down

0 comments on commit 37df366

Please sign in to comment.