Documente Academic
Documente Profesional
Documente Cultură
LEAP YEAR
<html>
<script>
function checkLeap() {
year = parseInt(document.first.year.value,10);
if (year%4>0)
leap="not a leap year";
else {
else
leap="is a leap year";
}
document.first.leap.value = leap;
// end of function
}
</script>
<body>
<form name = "first">
<p> Input year :<input type=text name="year" size=4> </p>
<p> <input type=text name="leap" size=20 > </p>
<p> <input type=button value="Leap Year?" onClick="checkLeap()"> </p>
</form>
</body>
</html>
If (conditions) {
alert(“no year input”)
}
We do not need the else part of the structure because if the input is not an empty string
then then everything is fine.
We should also check that the user has input a number rather than text, i.e. 2004 rather
than two thousand and four. This check is discussed in chapter 3.