Return to Kroll Web Design home page

JavaScript Tutorials

« Return

if statement

With if statements, make sure to enclose the conditions in parens, and to enclose the actions in curly braces:

Code:

<script type="text/javascript"> //<![CDATA[

a = 1;
b = 1;

if (a == 1) { document.write("fyi: a is equal to 1 <br><br>"); }

if (a == b) { document.write("a and b are equal"); }
else { document.write("a and b are not equal"); }

</script>

Output:




©2010 Kroll Web Design    davidarthurkroll@verizon.net    781.910.3694