OR and AND

The if-then statements we've seen so far are pretty simple. You might, however, want to add more conditions to an if-then statement (for example, "If Joe is in high school and is not doing his homework, then tell him to get to work"). To add more conditions to an if-then statement, use the OR and AND operators.

OR

Suppose you want to give different greetings to people who come to your site, depending on who they are. You could, as in Figure 3-6, use a prompt box to ask for a visitor's name (Figure 3-7) and then use an if-then statement to determine which greeting to give.

Asking for a visitor's name with the prompt box

Figure 3-6. Asking for a visitor's name with the prompt box

Figure 3-7. The ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.