Skip to content

Commit

Permalink
added age in year
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagar-Sharma-7 committed Jun 20, 2022
1 parent a6f4a8f commit 3a80c22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h1 id="heading"></h1>
<p id="sub_heading"></p>
</div>
<div class="hidden_section">
<p>Years: <span id="years"></span></p>
<p>Months : <span id="months"></span></p>
<p>Weeks : <span id="weeks"></span></p>
<p>Days : <span id="days"></span></p>
Expand Down
6 changes: 5 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const cal = document.querySelector(".calculate");
const github = document.querySelector("#github");

// result span
const year_span = document.querySelector("#years")
const month_span = document.querySelector("#months");
const week_span = document.querySelector("#weeks");
const day_span = document.querySelector("#days");
Expand Down Expand Up @@ -49,6 +50,7 @@ cal.addEventListener("click", () => {
const ageInHours = ageInDays * 24;
const ageInMin = ageInHours * 60;
const AgeInSec = ageInMin * 60;
const ageInYears = Math.floor(ageInMonths / 12)

// console.log(`month = ${ageInMonths}, days = ${ageInDays}, hours = ${ageInHours}, min = ${ageInMin}, seconds = ${AgeInSec}`);
if (dob.value == ""){
Expand Down Expand Up @@ -87,6 +89,7 @@ cal.addEventListener("click", () => {
$(".heading_section").slideUp(150);
$(".hidden_section").slideDown(150);
const animation = setInterval(() => {
year_span.innerHTML = Math.floor(Math.random() * 10);
month_span.innerHTML = Math.floor(Math.random() * 100);
week_span.innerHTML = Math.floor(Math.random() * 1000);
day_span.innerHTML = Math.floor(Math.random() * 10000);
Expand All @@ -97,7 +100,8 @@ cal.addEventListener("click", () => {

setTimeout(() => {
clearInterval(animation);
month_span.innerHTML = ageInMonths;
year_span.innerHTML = ageInYears;
month_span.innerHTML = ageInMonths;
week_span.innerHTML = ageInWeeks;
day_span.innerHTML = ageInDays;
hour_span.innerHTML = ageInHours;
Expand Down

0 comments on commit 3a80c22

Please sign in to comment.