O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Conditional Blocks of Code

if (age >= 100){   document.write("Wow you are a centurian!"); } else if (age >= 18) {   document.write("You are an adult."); } else {   document.write("You are a child."); }

If blocks are created using the basic if (comparison) {IF_BLOCK}. The if block can be followed up by an additional else block using else{ELSE_BLOCK}. In addition, you can add a condition to the else block using else(condition){ELSE_BLOCK}.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required