Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Or Statement

Reply
Thread Tools

Or Statement

 
 
BillyZ
Guest
Posts: n/a
 
      07-21-2008
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
};
 
Reply With Quote
 
 
 
 
Henry
Guest
Posts: n/a
 
      07-21-2008
On Jul 21, 4:48*pm, BillyZ <(E-Mail Removed)> wrote:
<snip>
> #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.

 
Reply With Quote
 
 
 
 
Tim Streater
Guest
Posts: n/a
 
      07-21-2008
In article
<(E-Mail Removed)>,
BillyZ <(E-Mail Removed)> wrote:

> 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')) {
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      07-22-2008
In comp.lang.javascript message <449a2b9e-c3f5-4447-b323-18f8aa2e763d@34
g2000hsf.googlegroups.com>, Mon, 21 Jul 2008 08:48:53, BillyZ
<(E-Mail Removed)> posted:

>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.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      07-22-2008
Tim Streater wrote:
> BillyZ <(E-Mail Removed)> wrote:
>> 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')) {


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>
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
Which of switch statement and if-else statement takes less time to execute? swaroophr@gmail.com C Programming 21 08-02-2005 09:24 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments