
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Logical Operators
|
131
The Logical Operators
In Chapter 4, we saw how to make logical decisions using conditional expressions
and Boolean values. The decisions were based on single factors: if a movie hasn’t
loaded, don’t start playing; if a spaceship has double-shot power, increase the dam-
age its shots inflict; and so on. Not all programming logic is so simple. We’ll often
want to consider multiple factors in our branching (i.e., decision-making) logic.
Suppose, for example, that we are making a personalized Flash site that requires
users to log in. If a user logs in as a guest, the content he can see is limited. When a
registered user logs into the site, we set a variable that indicates, for the duration of
our movie, that the user is allowed to see privileged content:
var userStatus = "registered";
To decide whether to allow access to a restricted area, we use a Boolean check like
this:
if (userStatus = = "registered") {
// It's okay, let 'em in...
}
Suppose we want to demonstrate the site to prospective investors without forcing
them to register and without showing them material reserved for registered users.
We can invent a new user category, “specialGuest”, that allows investors to see more
than a guest but not as much as a registered user. When we want to identify some-
one as ...