Skip to content

AmanMishra https://github.com/AmanMishra04 #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions AmanMishra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script>

// Javascript program for age calculator

// function to calculate current age
function findAge(current_date, current_month, current_year, birth_date,
birth_month, birth_year)
{
// days of every month
month = [31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31 ]

// if birth date is greater then current birth
// month then do not count this month and add 30
// to the date so as to subtract the date and
// get the remaining days
if (birth_date > current_date) {
current_date = current_date + month[birth_month - 1];
current_month = current_month - 1;
}

// if birth month exceeds current month, then do
// not count this year and add 12 to the month so
// that we can subtract and find out the difference
if (birth_month > current_month) {
current_year = current_year - 1;
current_month = current_month + 12;
}

// calculate date, month, year
var calculated_date = current_date - birth_date;
var calculated_month = current_month - birth_month;
var calculated_year = current_year - birth_year;

// prvar the present age
document.write("Present Age<br>Years: "+(calculated_year)+" ");
document.write("Months: "+calculated_month+" ");
document.write("Days: "+calculated_date+" ");
}

// driver code to check the above function
// current dd// mm/yyyy
var current_date = 7;
var current_month = 12;
var current_year = 2017;
// birth dd// mm// yyyy
var birth_date = 16;
var birth_month = 12;
var birth_year = 2009;
// function call to prvar age
findAge(current_date, current_month, current_year,
birth_date, birth_month, birth_year);

</script>