Monday, November 16, 2015

Leap Year in JavaScript

A simple program that I wrote using HTML form and JavaScript to check if the given year of the user is leap year or not a leap year.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<style>
body,p {

  font-family:arial;
  font-size:16px;
 }
</style> 
<body>
<h3> Leap Year Checker </h3>
<br/>Enter a Year
<input type="text" id="num_value" name="num_value" size="5">
<br><br>
<button onclick="check_year()">Check Year</button>
<br><br>
<p id="demo"></p>
<script>
  function check_year() {
    var  year= document.getElementById("num_value").value;
   
   if(year%4 == 0)
      {
          if( year%100 == 0) /* Checking for a century year */
          {
              if ( year%400 == 0)
                 result =  year + " is a Leap Year.";
              else
                result =  year +" is not a Leap Year.";
          }
          else
             result =  year + " is a Leap Year.";
      }
      else
         result =  year +" is not a Leap Year.";
   
     document.getElementById("demo").innerHTML = result;
  }
</script>
</body>

</html>


No comments:

Post a Comment