Thread: Age calculator

Results 1 to 4 of 4
  1. #1
    goten`'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    Mars
    Posts
    1,213
    Reputation
    24
    Thanks
    174
    My Mood
    Bored

    Age calculator

    I'm making a age calculator using only javascript not actual java. I'm a beginner doing this and I have some problems in it.

    I have done the basic calculation of months and years but having trouble at the part that some months have 31 days in them.

    Please look at my code and help me out. The following code is all I know about javascipt yet so I wouldn't any new codes that you might mention.

    Code:
    <html>
    <head><title>Assignment 5</title>
    
    <script language="JavaScript">
    <!-- hide me
    // variables past
    var month = prompt("What month were you born in?", "1-12");
    
    var year = prompt("What year were you born in?" , "1994");
    
    //variables present
    
    var month_pre = prompt("What month is it now?" , "1-12");
    var year_pre = prompt("What year is it now?" , "2011");
    
    var days_per_year = ("365");
    var days_per_month = ("30");
    
    var age_1 = (year_pre - year)
    var age_2 = (month_pre - month)
    var age_3 = (age_1 * days_per_year)
    var age_4 = (age_2 * days_per_month)
    var age_5 = (age_3 + age_4)
    var age_6 = (age_5)
    // switchers
    switch (month)
    {
      case '1': (age_6 - (1 * age_1));
                break;
      case '2': (age_6 - (1 * age_1));
                break;
      case '3': (age_6 - (2 * age_1));
                break;
      case '4': (age_6 - (2 * age_1));
                break;
      case '5': (age_6 - (3 * age_1));
                break;
      case '6': (age_6 - (3 * age_1));
                break;
      case '7': (age_6 - (4 * age_1));
                break;
      case '8': (age_6 - (5 * age_1));
                break;
      case '9': (age_6 - (5 * age_1));
                break;
      case '10': (age_6 - (6 * age_1));
                break;
      case '11': (age_6 - (6 * age_1));
                break;
      case '12': (age_6 - (7 * age_1));
                break;
      default:  document.write("You're stupid<br />")
    }
    
    //written part
    document.writeln("<b>You were born on " + month + " of " + year + " which makes you " + age_6 + " days old</b>");
    
    
    // end hide -->
    
    </script>
    
    <head>
    <body bgcolor="white">
    </body>
    </html>
    I have using Adobe dreamweaver for this.

    Important rules for all the idiots:

    1st rules of spelling. Don't fuck with the ORIGINAL.


    There're three things I refuse to tolerate: cowardice, bad haircuts, and millitary insurrection.

    - Frieza

    You want to keep everyone from dying? That's naive. It's a war; people die.

    - Luffy to Vivi in Alabasta


    We shouldn't worry about being able to achieve our dreams, as long as we have the desire to do it!

  2. #2
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,321
    My Mood
    Cheeky
    years = currentyear-birthyear-1
    if(curmonth > birthmonth)
    years += 1;
    else if(curmonth == birthmonth && curday >= birthday)
    years += 1;

    born on: 5 october 1992
    current date: 17 november 2011
    2011-1992-1 = 18
    october < november so years += 1, my age is 19.

    Seems a lot easier then what you're doing :\
    Ah we-a blaze the fyah, make it bun dem!

  3. The Following 2 Users Say Thank You to Hell_Demon For This Useful Post:

    goten` (11-18-2011),Hassan (11-17-2011)

  4. #3
    Threadstarter
    It's a war, People die.
    MPGH Member
    goten`'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    Mars
    Posts
    1,213
    Reputation
    24
    Thanks
    174
    My Mood
    Bored
    Quote Originally Posted by Hell_Demon View Post
    ;
    else if(curmonth == birthmonth && curday >= birthday)
    years += 1;
    What are you referring to here where it says 'birthday'?

    Important rules for all the idiots:

    1st rules of spelling. Don't fuck with the ORIGINAL.


    There're three things I refuse to tolerate: cowardice, bad haircuts, and millitary insurrection.

    - Frieza

    You want to keep everyone from dying? That's naive. It's a war; people die.

    - Luffy to Vivi in Alabasta


    We shouldn't worry about being able to achieve our dreams, as long as we have the desire to do it!

  5. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,321
    My Mood
    Cheeky
    day of birth, as in day of the month.

    Sorry, I'm not that active around here so didn't notice it anytime earlier.
    Ah we-a blaze the fyah, make it bun dem!

Similar Threads

  1. Age of Mythology
    By Takuni in forum General Game Hacking
    Replies: 1
    Last Post: 03-11-2008, 05:44 AM
  2. Tu age?
    By radnomguywfq3 in forum General
    Replies: 32
    Last Post: 11-08-2007, 08:23 AM
  3. OMG i lied about me age...OMG
    By BluSpex in forum General
    Replies: 14
    Last Post: 09-03-2007, 08:51 PM
  4. Age of Empire
    By Tranger in forum Hack Requests
    Replies: 0
    Last Post: 02-04-2006, 05:39 PM
  5. Dark Age of Camelot
    By iamapyro in forum General Gaming
    Replies: 4
    Last Post: 01-27-2006, 06:02 AM