Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Need help with JavaScript!

Options
  • 05-12-2006 10:25pm
    #1
    Closed Accounts Posts: 30


    I am an amateur, having some trouble with my javascript, I am trying to make a app that can tell you what year was a leap year ad what year wasnt.
    As I have only started learning JavaScript last night I might not the greatest.
    I was thinking that if I could get a operator that is odd or even that might help. So if anyone could advise me and help clean it up a bit that would be great

    Help would really be appreciated.
    <html>
    <head>
    <script type="text/javascript">
    var leap = 4 
    alert("Click OK")
    
    var yes  = prompt("Enter a year to find out if that year was a leap year", "4")
    
    leap     *= parseInt(yes)
    alert("Even number= Leap year" + '\n' + "odd numbers=not a leap year" + '\n' + "OK go" + leap + "!!")
    </script>
    </head>
    <body>
    </body>
    </html>
    


Comments

  • Registered Users Posts: 32,136 ✭✭✭✭is_that_so


    An explanation on Leap Years. You might want to look at mod or remainder. E.g. 20 % 2=0
    Google for "javascript examples tutorials" . Tons of stuff out there.


  • Closed Accounts Posts: 30 as_seen_on


    is_that_so wrote:
    An explanation on Leap Years. You might want to look at mod or remainder. E.g. 20 % 2=0
    Google for "javascript examples tutorials" . Tons of stuff out there.
    could you show me what you mean by 20 % 2=0, I dont really understand the % part.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    as_seen_on wrote:
    could you show me what you mean by 20 % 2=0, I dont really understand the % part.
    The modulo operator (%) divides the two numbers and returns the remainder, such as 20%2=0 above, or 14%5=4 (5 goes into 14 twice with 4 remaining), etc.


  • Registered Users Posts: 32,136 ✭✭✭✭is_that_so


    Opps sorry. Assuming too much.:o


  • Closed Accounts Posts: 4 boondog


    Divide the given 4-digit year by 4 and/or 400. Any result where rest = zero is a leapyear.


  • Advertisement
Advertisement