Or Statement

B

BillyZ

I am implementing a conditional menu. The script below is evaluating
to see if I am on either of two specific pages. I have done it two
different way's and both are below.
Thanks in advance.

#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
nacSecondary = true;
} else {
nacSecondary = false
};

#2 This returns true all the time.
if (pageName == 'nacPartnerPage' || 'networkAccessPage') {
nacSecondary = true;
} else {
nacSecondary = false
};
 
H

Henry

#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
<snip> ^ ^

Unlikely. Without those two inner parentheses it might return false
all of the time. With them the above is equivalent to your second
attempt.
 
T

Tim Streater

BillyZ said:
I am implementing a conditional menu. The script below is evaluating
to see if I am on either of two specific pages. I have done it two
different way's and both are below.
Thanks in advance.

#1 This returns false all the time.

if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {

This is not how you do an "or". You need to write:

if ((pageName=='nacPartnerPage') || (pageName=='networkAccessPage')) {
 
D

Dr J R Stockton

In comp.lang.javascript message <449a2b9e-c3f5-4447-b323-18f8aa2e763d@34
g2000hsf.googlegroups.com>, Mon, 21 Jul 2008 08:48:53, BillyZ
if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
nacSecondary = true;
} else {
nacSecondary = false
};

Additionally, there is no need to write
if (A) B = true ; else B = false
which should be written
B = A
and is reversed by
B = !A

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
T

Thomas 'PointedEars' Lahn

Tim said:
This is not how you do an "or". You need to write:

if ((pageName=='nacPartnerPage') || (pageName=='networkAccessPage')) {

Another, less compatible possibility[1] is

if (pageName in {nacPartnerPage: 1, networkAccessPage: 1}) {

(provided one has not augmented Object.prototype).

But the `if' statement really is superfluous here:

nacSecondary = (one_of_the_suggested_boolean_expressions);


PointedEars
___________
[1] <http://PointedEars.de/es-matrix#i>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top