Home > Articles

  • Print
  • + Share This
This chapter is from the book

Conditional Statements

While event handlers notify your script when something happens, you may want to check certain conditions yourself. For example, did the user enter a valid email address?

JavaScript supports conditional statements, which allow you to answer questions like this. A typical conditional uses the if statement, as in this example:

if (count==1) alert("The countdown has reached 1.");

This compares the variable count with the constant 1, and displays an alert message to the user if they are the same. You will use conditional statements like this in most of your scripts.

NOTE

You'll learn more about conditionals in Hour 6, "Testing and Comparing Values."

  • + Share This
  • 🔖 Save To Your Account