enter any year than display the leap or not
find the leap year by using for loop
Collapse
X
-
You don't need for loop to determine if leap year or not. Try this code I made.
Code:<html> <head> <title>Zick Sample</title> <script> function leapyear() { var year = document.getElementById("inputyear").value; if(year != "") { if ((year % 4 == 0) && year % 100 != 0) { alert(year + " is a leap year."); } else if (year % 400 == 0) { alert(year + " is a leap year."); } else { alert(year + " is not a leap year."); } } } </script> </head> <body> <form method="post" action="javascript:;"> <input type="text" id="inputyear" placeholder="Enter the year."><br> <input type="submit" value="Submit" onclick="leapyear()"> </form> </body> </html>
Comment