forked from pranjay-poddar/Dev-Geeks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Age Calculator. You enter the date of birth and it tell you how many years are you. I hope you like this program. Please if it is okay for you, could you put the hacktoberfest or hacktoberfest accepted label? Thank you so much for the opportunity to contribute!!
- Loading branch information
1 parent
d6ab5ff
commit a89351d
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<html> | ||
<head> | ||
<script> | ||
function ageCalculator() { | ||
var userinput = document.getElementById("DOB").value; | ||
var dob = new Date(userinput); | ||
if(userinput==null || userinput=='') { | ||
document.getElementById("message").innerHTML = "**Choose a date please!"; | ||
return false; | ||
} else { | ||
|
||
//calculate month difference from current date in time | ||
var month_diff = Date.now() - dob.getTime(); | ||
|
||
//convert the calculated difference in date format | ||
var age_dt = new Date(month_diff); | ||
|
||
//extract year from date | ||
var year = age_dt.getUTCFullYear(); | ||
|
||
//now calculate the age of the user | ||
var age = Math.abs(year - 1970); | ||
|
||
//display the calculated age | ||
return document.getElementById("result").innerHTML = | ||
"Age is: " + age + " years. "; | ||
} | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<center> | ||
<h2 style="color: 32A80F" align="center"> Calculate Age from Date of Birth <br> <br> </h2> | ||
|
||
<!-- Choose a date and enter in input field --> | ||
<b> Enter Date of Birth: <input type=date id = DOB> </b> | ||
<span id = "message" style="color:red"> </span> <br><br> | ||
|
||
<!-- Choose a date and enter in input field --> | ||
<button type="submit" onclick = "ageCalculator()"> Calculate age </button> <br><br> | ||
<h3 style="color:32A80F" id="result" align="center"></h3> | ||
</center> | ||
</body> | ||
</html> |