Announcement

Collapse
No announcement yet.

Java script question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java script question

    I am tryying around with a book called "Learn how to program". My first challenge came up when I put in the following code and gedit called the ">" an end of statement. It is this line "" onClick='var status = (userAge.value >=21) ? "an adult" "

    Here is the code that is supposed let you type your age in a box to let you know if you are over or under 21.

    *note: I am using gedit and Firefox in Linux Mint

    <HTML>
    <BODY>
    <FORM>
    Enter Your Name:
    <INPUT TYPE=text NAME=UserName Value="Harry Potter">
    Enter Your Age:
    <INPUT TYPE=text Name=UserAge Value="12">
    <INPUT TYPE=button VALUE ="Check Age"
    onClick='var status = (userAge.value >=21) ? "an adult" : "a minor";
    alert (userName.value + " is " + status + ".");'>
    </FORM>
    </BODY>
    </HTML>

    ________________

    sakibpavel

  • #2
    I don't understand if your asking for help and the code isn't working how you want it to work??

    instead of asking someone for their age... most websites actually asks the user for their birthday.

    you just take the year they were born and then take today's year and minus it from the year they were born. Then compare it.

    I would instead write a javascript function.

    in the html keep the onclick=function_name()

    then in the function have 2 variables... one is todays year... and the other grabs what the users birth year was that they gave.

    then Have 2 variables and a if statement... store the result from the age computation... and then do a if statement or a case switch. where if var age > 21 " your old enough" if var age is < 21 = " your too young sorry.

    I didn't provide you with any code just concept.

    If you directly ask someone if your 21 years old... most will say yes I am 21... but younger kids might not quickly understand if you ask them for their birthday... they might put their real birthday in the forms... because it forces them to think at some level to make sure their birthday year they put down is 21 or older.

    Comment

    Working...
    X