HTML and CSS Reference
In-Depth Information
If you need to check for more than one condition, you can nest the
if...else statements.
The first condition
is the same as before.
if (y % 2 == 0) {
} else if (y % 3 == 0) {
console.log('Divisible by 3');
} else {
console.log('Not a multiple');
if the condition
is false, check
another condition.
An alternative to if...then...else is the switch statement. It lets you
choose from a long list of alternatives based on the value of a variable.
It doesn't allow the flexibility of if...then...else in comparison opera-
tions but does offer a more easily comprehensible way of presenting
multiple choices.
Inside the brackets
is a variable to be
This is an example of
a method on an
object. more in
"Functions and objects.''
switch (z.toLowerCase()) {
case "eat me":
case "drink me":
console.log('Why is a'
+' raven like a'
+ 'writing desk?');
The variable
passed in is
compared to
each of the
cases in turn.
Each case
is ended
by a break .
If none of the
cases match,
the default
is used.
Search WWH ::

Custom Search