Create a JavaScript Function with the name age () this function will take your date of birth as parameters and return your age in years.

// To calculate age:
var year_born = prompt("Please enter your date of birth:", "Type here");
var d = new Date();
var n = d.getFullYear();
function getAge(birthYear){
	var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    age = currentYear - birthYear;
    return age;
}
calculatedAge = getAge(year_born);
alert("Hello, " + "you are " + calculatedAge + " years old!");

4
4
Awgiedawgie 440220 points

                                    function Person(dob) {
  // [1] new Date(dateString)
  this.birthday = new Date(dob); // transform birthday in date-object
  
  this.calculateAge = function() {
    // diff = now (in ms) - birthday (in ms)
    // diff = age in ms
    const diff = Date.now() - this.birthday.getTime(); 
    
    // [2] new Date(value); -> value = ms since 1970
    // = do as if person was born in 1970
    // this works cause we are interested in age, not a year
    const ageDate = new Date(diff); 
    
    // check: 1989 = 1970 + 19
    console.log(ageDate.getUTCFullYear()); // 1989
    
    // age = year if person was born in 1970 (= 1989) - 1970 = 19
    return Math.abs(ageDate.getUTCFullYear() - 1970);
  };
}
var age =new Person('2000-1-1').calculateAge();
console.log(age); // 19

4 (5 Votes)
0
4.09
11
Awgiedawgie 440220 points

                                    function test(name, birth_year, current_year) {

  const age = current_year - birth_year;

  const response = name + " is " + age;

  return response;

}

test("john", 1894, 1917)

4.09 (11 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to get age in javascript get age with day.js calculate age from date of birth dayjs simple age calculator in js get age javascript age and date of birth html javascript javascript register date of birth to age takes the age in years and returns the age in days javascript how to code a check age function in javascript check age js convert date of birth to age in javascript age calculator from date of birth javascript function to calculate age in javascript get age from date of birth js function to calculate age from date of birth in javascript how to use date to calculate date of birth javascript javascript calculate age from date of birth in months javascript age from date of birth how to make an age calculator in javascript check age based on date of birth in javascript get age by date of birth in java script How do I calculate someone's age based on a DateTime type birthday? in js js date of birth calculate your date of birth javascript age from birth date js date of birth using js calculate age by birthday javascript calculate date of birth from age in javascript and return only value automatically calculate age from date of birth javascript javascript''> function to calculate age from date of birth entered in a datepicker calculate age in years javascript age calculator js age calculation formula in javascript calculate age by date of birth and todays date using javascript date to age and age to dob in js age calculator javascript how can i show my birth days in javascript convert date of birth to age with javascript how to calculate age based on date of birth in javascript convert age into date of birth js js work out age from dob calculate age with timestamp in js how to find age of person using javascript avascript Calculate age by date of birth javascript date of birth javascript get age by birth date calculate age in js get birth year from age in javascript Calculate date of birth from age in JavaScript how to find age in days javascript how to check age js calculate age in days using date of birth in javascript calculate age using date object js how to find age in javascript javascript's age how to find age from date of birth timestamp in javascript calculating age from dob in javascript claculate age from birthdate in javaScript javascript function to calculate age from date of birth entered in a datepicker birth date via age in js javascript display current age Javascript to calculate age based on DOB how age calculate online by date of birth using javascript javascript count age find the age in javascript get age javascript js date of birth how to calculate current age from date of birth in javascript only years get birth date from age js how to turn age to birth date in js javascript calculate age from date Calculate date of birth from age JavaScript detect age from date js javascript calculate age from date of birth check age in javascript calculate age function javascript how to get the age of given birth date in an object javascript How to get the age of given birth date in javascript How to get the age of given birth date in javascript" how to make a date of birth from javascript how to culculate age according to date of birth js age calculate js return age from date js input your DOB(date) through prompt. for example date is "24" work out birthday from current date react calculate age with todays age node js javascript calculate age by date of birth javascript work out how old someone is based on their birthday javascript get exact age from date calc common age js get age from current date javascript javascript find age from birthdate age calculation in javascript convert age to days using form js js birth age js calculater age Check age JavaScript javascript age calculator from date of birth js know how old someone is javascript calculating age from date of birth age calculate in javascript Javascript calculate birth date javascript calculate age using arrow function node.js age counting age calculat birthdate js how to calculate the age in javascript age javascript age from date javascript Write a function that take birth date and returns Age in years, months and days js javascript get the age from date how to calculate birth year from age in javascript store birth year in variable javascript node js age counting javascript code to calculate age from date of birth calculate age given date in js javascript calculate someone's age javascript calculate someones age node js calculate age how to return age year in number in js get date of birth from age javascript get year of birth from age javascript convert date to age in javascript js calc age date to age calculator in javascript javascript calculate date of birth calculate age from date of birth js how to calculate your age get age from date of birth js function to calculate age How to determine age by dateof birth javascript js input date of birth calc javascript date of birth calculator age find with date of birth js calculate age based on date of birth using javascript from age to date of birth javascript javascript get age from date of birth calculate age today in dayjs bitrthdate javascript calculate age using form js age calculate using js stack overflow age js calculate age using date of birth in javascript javascript calc age js calculate age year calculator for age code in javascript get age from dob js time and date stamp to calculate aging javascript date to age javascript var age = {person} how to count age by date of birth in vuejs site:stackoverflow.com how to count age by date of birth in vuejs how get current age in react javascript calculate age based on date of birth age of java script calculate exact age from date of birth javascript get your age using dates js javascript birthday date javascript calculate age from birthdate calculate age formula javascript how to calculate age javascript how to get current age from date of birth javascript number day determinate age on earth js calc age in js show birthdate in js calculate birthdate javascript js birthday to age calcage (20) javascript javascript function calculate age date birth get age from date javascript from date to age function javascript how to calculate a person's age with javascript get age from dob javascript javascript calculate age javascript age calculate age from date of birth in nodejs Create a JavaScript Function with the name age () this function will take your date of birth as parameters and return your age in years. method to compute age from birth year js calculate age from date javascript get age from date in javascript js calculate age by date js get age javascript birth year js age from date js date from birth calculate age from date of birth js calculate age function javascipt javascript calculate age in years from date of birth javascript date to age get age by string value in javascript birth year javascript how to get age from birth year in js year of birthday calculator javascript calculate age from year of birth in javascript calculate age from date of birth in javascript calculate age by birthdate js calculate dob from age in javascript check age number in javascript function html check age number in javascript function function to check age in javascript how to calculate age in javascript get age from date of birth javascript find age from date of birth javascript javascript calculate age from integer read a number in javascript and return age Javascript to calculate user's age, based on DOB in javascript Javascript to calculate user's age, based on DOB age method js age mwthod js format age in age group in javascript age function in javascript get date of birth javascript get date of birth in age javascript get age according to date js get age according two date js javascript calculate afe js according to bday age javascript function take birthdate and return age calculate age using DAte js get age from date js calculate age js javascript work out age from date of birth js get age from date javascript calculate age todays date how to find someone's date of birth from date in javascript calculate age acurate javascript calculate current age java script calculate age from dob in javascript javascript code to calculate age in years age calculation in js javascript age difference validation calculating age in javascript through date function dob js how to calculate age from date of birth javascript calculate age by birth date javascript js date to age get a person's age with two javascript dates how to calculate age from date.parse values calculate age in javascript javascript html get age javascript get age javacript age from date javascript calculate born date How to calc age js calculating age using Javascript convert age to days from birthday javascript how to calculate age in days in javascript using return how to determine the age and days in javascript to a given date of birth js dob to years javascript funtion to calculate age above 18 compare value to the date() to obtain age javascript how to calculate your birthday using javascript get year with a birth date to methods javascript birthday to age javascript js calculate age function how to check age in javascript how to calculate age in js get current age by birthday js use javascript to get age convert year into age jquery get age in javascript clacualting age in js calculate age from date of birth in node js calculate age from birthdate javascript javascript age from birthdate how to find age javascript how to find age today in javascript write a function in js that calculates the born day calculate age at certain year in javascript is there a function in javascript to calculate age in date javascript function to calculate age from date of birth javascript get age from date calculate age javascript get exact age from data js determine someons exact age with Date Object js age from date function javascript calculate age using date of birth javascript javascript age from date method to calculate age from date of birth in javascript get date of birth from user html js calculate age from dob js javascript get birthdate with minimum age calculate age from date of birth javascript how to calculate age from date of birth js how to calculate age from date of birth in javascript javascript get birthday javascript age function check specific age based on day js calculate age from dob html javascript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source