Jump to content

computing age in javascript


Guest montee_soree
 Share

Recommended Posts

Guest montee_soree

please help me with this code (below) it seems that it doesn't work.. i think there's no problem with it.. please help me.. what seems to go wrong..// beginning of code<html><head></head><body><script language = "JavaScript"> var d = new Date(); document.write('Date in mm-dd-yyyy format: '); document.write(d.getMonth()+1); document.write('-'); document.write(d.getDate()); document.write('-'); document.write(d.getFullYear()); document.write('<br><br>'); document.write('Time in hh:mm:ss format: '); document.write(d.getHours()); document.write(':'); document.write(d.getMinutes()); document.write(':'); document.write(d.getSeconds()); yearnow = d.getFullYear() daynow = d.getDate()function age(form){ yearbirth = eval(form.yearbirth.value) monthbirth = eval(form.monthbirth.value) daybirth = eval(form.daybirth.value) yearold = (yearnow-1) - yearbirth For (x=monthbirth + 1; x<=13; x++ ) { monthbirth = monthbirth + 1 } If (monthbirth == 12) { yearold = yearold + 1 monthbirth = 0 } dayold = 31 - daybirth dayold = dayold + daynow If (dayold >= 31) { monthbirth = monthbith + 1 If (monthbirth == 12) { yearold = yearold + 1 monthbirth = 0 } dayold = dayold - 31 } form.yearsold.value = yearold form.monthsold.value = monthbirth form.daysold.value = dayold}</script><form name = "form">Month:<input type="number" name = "monthbirth"><br>Day:<input type="number" name = "daybirth"><br>Year:<input type="number" name = "yearbirth"><br><input type="button" value="compute" onClick="age(this.form)"><br>you are <input type="number" name = "yearsold"> years and <input type="number" name = "monthsold"> months and <input type="number" name = "daysold"> days old.</form></body></html>//end of codethnks for your help..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...