www.webdeveloper.com
Results 1 to 3 of 3

Thread: javascript starter help

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    4

    javascript starter help

    what's wrong with this code


    Code:
    <html>
    <body>
    <script>
    var age=prompt("what's your age")
    var gen=prompt("what's your gge")
    if
    (age>=21 && gen=male) || (age>=18 && gen=female)
    {
    document.write("eligble") 
    }
    else
    {
    document.write("not eligble")
    }
    </script>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    778
    With your if statement grouping, you are missing an extra parenthesis for each pairing which breaks that if statement.
    Also the comparison of the gen variable needs to use the == comparison operater (just a single = sets a variable, 2 or 3 = signs will compare).
    And the male and female comparison strings much be enclosed in some form of a quote.
    It also would be proper practice to use semi-colons at the end of each proper line of code:
    Code:
    <html>
    <body>
    <script>
    var age=prompt("what's your age");
    var gen=prompt("what's your gge");
    if((age>=21 && gen=="male") || (age>=18 && gen=="female")) {
      document.write("eligble");
    } else {
      document.write("not eligble");
    }
    </script>
    </body>
    </html>
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Jan 2013
    Posts
    4
    tons of thanks sir problem solved and i have learned something very important

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles